使用SQL脚本创建用户,映射到数据库并将角色分配给该数据库 [英] Creating a user, mapping to a database and assigning roles to that database using SQL scripts

查看:457
本文介绍了使用SQL脚本创建用户,映射到数据库并将角色分配给该数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前是这样做的,但不是通过脚本完成的.我必须在SQL Server(SQL身份验证)中创建一个新用户,并将该用户映射到数据库,然后使用SQL脚本将该用户的角色分配给该数据库.

I've done this before but not through scripts. I've to create a new user in SQL server (SQL Authentication) and map the user to a database and assign the roles for the user to that database using SQL scripts.

我该怎么办?

推荐答案

尝试:

CREATE USER [Username] FOR LOGIN [Domain\Username]
EXEC sp_addrolemember N'DatabaseRole', N'Username'

显然将用户名",域\用户名"和数据库角色更改为您希望授予其权限和访问级别的用户名,例如"db_datareader"

Obviously changing Username, and Domain\Username and the database role to being the username that you wish to grant rights to and the level of access, such as 'db_datareader'

这篇关于使用SQL脚本创建用户,映射到数据库并将角色分配给该数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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