Adds a security account as a member of an existing Microsoft® SQL Server™ database role in the current database.
sp_addrolemember [@rolename =] 'role',
[@membername =] 'security_account'
0 (success) or 1 (failure)
When using sp_addrolemember to add a security account to a role, any permissions applied to the role are inherited by the new member.
When adding a SQL Server role as a member of another SQL Server role, you cannot create circular roles. For example, MyRole cannot be added as a member of YourRole if YourRole is already a member of MyRole. Additionally, you cannot add a fixed database or fixed server role, or dbo to other roles. For example, the db_owner fixed database role cannot be added as a member of the user-defined role YourRole.
Only use sp_addrolemember to add a member to a SQL Server role. Use sp_addsrvrolemember to add a member to a fixed server role. Adding a member to a Windows NT group in SQL Server is not possible.
sp_addrolemember cannot be used inside a user-defined transaction.
Only members of the db_securityadmin or db_owner fixed database role can execute sp_addrolemember to add a member to fixed database roles. Role owners can execute sp_addrolemember to add a member to any SQL Server role they own.
This example adds the Windows NT user Corporate\JeffL to the Sales database as user Jeff. Jeff is then added to the Sales_Managers role in the Sales database.
Note Because Corporate\JeffL is known as the user Jeff in the Sales database, the user name Jeff must be specified using sp_addrolemember.
USE Sales
GO
EXEC sp_grantdbaccess 'Corporate\JeffL', 'Jeff'
GO
EXEC sp_addrolemember 'Sales_Managers', 'Jeff'
This example adds the SQL Server user Michael to the Engineering role in the current database.
EXEC sp_addrolemember 'Engineering', 'Michael'
Adding a Member to a SQL Server Database Role | sp_grantdbaccess |
sp_addsrvrolemember | System Stored Procedures |
sp_droprolemember |