mssql给登录(用户)db_owner访问数据库 [英] mssql giving logins(users) db_owner access to database

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

问题描述

我们有一个测试数据库和一些测试登录,我们希望通过脚本给db_owner访问。通常我们必须进入登录并右键单击用户名,并转到用户映射并选择数据库关联它,并给它所有者访问,然后单击确定。感谢任何帮助

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. Thanks for any help

推荐答案

您需要做两件事,两者都运行在目标数据库的上下文中(即, code> USE(database)第一):

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 [LoginName]

  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或更高版本,您可以进入操作的UI,填写对话框(在这种情况下,将用户分配给数据库并添加角色),然后单击顶部的脚本按钮。而不是执行命令,它会将操作的脚本写入新的查询窗口。

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.

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

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