T-SQL How to grant role to user

2019-02-04 05:14发布

问题:

After creating roles and granting privileges to them, I want to grant the privileges of a specified role to a user, how to do with it? I tried grant to , but failed.

回答1:

EXEC sp_addrolemember 'db_owner', 'JohnJacobs'


回答2:

Because BOL shows sp_addrolemember has been deprecated, if you are using SQL Server 2012 you may want to use:

ALTER ROLE <role_name> ADD MEMBER <user_name>