Add User to Role
-
Posted on July 25, 2009 by Derek Dieter
-
0
To add a user to a role, you must use the stored procedure sp_addrolemember.
First you must select the database that contains the user and the role.
[cc lang=”sql”]
USE YourDatabaseHere
GO
EXEC sp_addrolemember ‘db_datareader’, ‘JohnJacobs’
EXEC sp_addrolemember ‘db_datawriter’, ‘JohnJacobs’
EXEC sp_addrolemember ‘db_accessadmin’, ‘JohnJacobs’
EXEC sp_addrolemember ‘db_backupoperator’, ‘JohnJacobs’
EXEC sp_addrolemember ‘db_ddladmin’, ‘JohnJacobs’
EXEC sp_addrolemember ‘db_denydatareader’, ‘JohnJacobs’
EXEC sp_addrolemember ‘db_denydatawriter’, ‘JohnJacobs’
EXEC sp_addrolemember ‘db_owner’, ‘JohnJacobs’
EXEC sp_addrolemember ‘db_securityadmin’, ‘JohnJacobs’
[/cc]
The example above shows all predefined roles in a database.
- Comments (RSS)
- Trackback
- Permalink
[…] Source 2: SQL Server Planer […]