SQL Server授予登录名(用户)db_owner访问数据库的权限 [英] SQL Server giving logins(users) db_owner access to database

查看:859
本文介绍了SQL Server授予登录名(用户)db_owner访问数据库的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个测试数据库和一些测试登录名,我们想让db_owner通过脚本访问。通常,我们必须先登录并右键单击用户名,然后转到用户映射,然后选择要与其关联的数据库并授予其所有者访问权限,然后单击 OK

We have a test database and some test logins that we would like to give db_owner access to through a script. Usually we would have to go into logins and right click on the username and go to user mapping and select the database to associate it with and give it owner access and click OK.

推荐答案

您需要做两件事,都在目标数据库的上下文中运行(即,执行 USE(数据库)首先):

You need to do two things, both running in the context of the target database (i.e., execute USE (database) first):


  1. 将该用户作为登录名添加到数据库: CREATE USER [LoginName ] FOR LOGIN [登录名]

  2. 将该用户添加到角色中: EXEC sp_addrolemember N'db_owner',N'LoginName'

  1. Add that user as a login to the database: CREATE USER [LoginName] FOR LOGIN [LoginName]
  2. Add that user to the role: EXEC sp_addrolemember N'db_owner', N'LoginName'

通常,如果您具有SQL Server Management Studio 2005或更高版本,则可以进入用户界面操作,请填写对话框(在这种情况下,将用户分配给数据库并添加角色),然后单击顶部的脚本按钮。代替执行命令,它会将用于操作的脚本写入新的查询窗口。

In general, if you have SQL Server Management Studio 2005 or higher, you can go into the UI for an operation, fill out the dialog box (in this case, assigning the user to the database & adding roles), and then click the "Script" button at the top. Instead of executing the command, it will write a script for the action to a new query window.

这篇关于SQL Server授予登录名(用户)db_owner访问数据库的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆