T-SQL How to grant role to user
Sql ServerSql Server-2008TsqlSql Server Problem Overview
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
Sql Server Solutions
Solution 1 - Sql Server
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>
Solution 2 - Sql Server
EXEC sp_addrolemember 'db_owner', 'JohnJacobs'
Solution 3 - Sql Server
In my case, I needed to add the user to the public role for a specific database. This is done as so:
USE [<DB Name>]
GO
CREATE USER [<User Name>] FOR LOGIN [<User Name>]
GO