时间:2021-07-01 10:21:17 帮助过:34人阅读
SQL 2012用户只能看到自己拥有权限的库 呢,下面给大家参考参考。
以SQL Server 2012 为例
上图是部分数据库的截图, 我们执行
- <table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7">
- <tbody><tr>
- <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td>
- <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7675')"></td>
- </tr>
- <tr>
- <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id="copy7675"><pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li>DENY VIEW any DATABASE to PUBLIC;</li></ol></pre>
- </td>
- </tr>
- </tbody></table>然后给Best库的Best用户执行
- <table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7">
- <tbody><tr>
- <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td>
- <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5818')"></td>
- </tr>
- <tr>
- <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id="copy5818"><pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li>ALTER AUTHORIZATION ON DATABASE::Best TO Best</li></ol></pre>
- </td>
- </tr>
- </tbody></table><img title="H80O8P922`NXMA2FRC~60AH" alt="H80O8P922`NXMA2FRC~60AH" width="350" height="181" src="https://www.gxlcms.com/help/uploads/allimg/c130422/13B600b92G0-251F.jpg">
资源管理器中Best用户登陆后就只能显示Best库了, 同样给Mine库的Mine用户执行相同SQL
- <table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7">
- <tbody><tr>
- <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td>
- <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy8201')"></td>
- </tr>
- <tr>
- <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id="copy8201"><pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li>ALTER AUTHORIZATION ON DATABASE::Mine TO Mine</li></ol></pre>
- </td>
- </tr>
- </tbody></table><img title="KM030PFB~D8GJO7R3CV%8YG" alt="KM030PFB~D8GJO7R3CV%8YG" width="353" height="163" src="https://www.gxlcms.com/help/uploads/allimg/c130422/13B600bb3620-35164.jpg">
Mine用户登录后也只能显示Mine数据库了, 达到了咱的目的, 分配权限的时候记得给对应用户映射对应数据库的权限, 防止跨库操作.