SQL 2012用户只能看到自己拥有权限的库 呢,下面给大家参考参考。
以SQL Server 2012 为例
本文来源gaodai.ma#com搞#代!码网_
上图是部分数据库的截图, 我们执行
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px" class="copyclass" id="copy7675"><pre class="prettyprint linenums">DENY VIEW any DATABASE to PUBLIC;
然后给Best库的Best用户执行
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px" class="copyclass" id="copy5818"><pre class="prettyprint linenums">ALTER AUTHORIZATION ON DATABASE::Best TO Best
资源管理器中Best用户登陆后就只能显示Best库了, 同样给Mine库的Mine用户执行相同SQL
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px" class="copyclass" id="copy8201"><pre class="prettyprint linenums">ALTER AUTHORIZATION ON DATABASE::Mine TO Mine
Mine用户登录后也只能显示Mine数据库了, 达到了咱的目的, 分配权限的时候记得给对应用户映射对应数据库的权限, 防止跨库操作.