Summary: in this tutorial, you’ll learn how to use the SQL Server ALTER ROLE statement to rename a role, add a member to a role, and remove a member from a role.
Introduction to the SQL Server ALTER ROLE statement #
The ALTER ROLE statement allows you to:
- Rename a role
- Add a member to a role
- Remove a member from a role
The following ALTER ROLE ... WITH NAME renames a role:
ALTER ROLE role_name
WITH NAME = new_name;
In this syntax:
- First, specify the name of the role after the
ALTER ROLEkeywords. - Second, specify the new role name in the
WITH NAMEclause.
To add a member to a role, you use the ALTER ROLE... ADD MEMBER statement:
ALTER ROLE role_name
ADD MEMBER database_principal;
In this statement, the database_principal is a database user or a user-defined database role. It cannot be a fixed database role or a server principal.
To remove a member from a role, you use the ALTER ROLE ... DROP MEMBER statement:
ALTER ROLE role_name
DROP MEMBER database_principal;
SQL Server ALTER ROLE statement examples #
We’ll use the BikeStores database for the following examples.
1) Using the SQL Server ALTER ROLE to rename a role #
First, create a new role called production:
CREATE ROLE production;
Second, rename the role production to manufacturing using the ALTER ROLE statement:
ALTER ROLE production
WITH NAME = manufacturing;
2) Using the SQL Server ALTER ROLE to add a member to a role example #
First, create a new login called robert:
CREATE LOGIN robert
WITH PASSWORD = 'Uikbm!#90';
Second, create a new user for the login robert:
CREATE USER robert
FOR LOGIN robert;
Third, add the user robert to the manufacturing role:
ALTER ROLE manufacturing
ADD MEMBER robert;
The following query verifies that the user robert is a member of the role manufacturing:
SELECT
r.name role_name,
r.type role_type,
r.type_desc role_type_desc,
m.name member_name,
m.type member_type,
m.type_desc meber_type_desc
FROM sys.database_principals r
INNER JOIN sys.database_role_members rm ON rm.role_principal_id = r.principal_id
INNER JOIN sys.database_principals m ON m.principal_id = rm.member_principal_id
WHERE r.name ='manufacturing';
Output:

3) Using the SQL Server ALTER ROLE to remove a member from a role example #
The following example uses the ALTER ROLE ... DROP MEMBER to remove the user robert from the role manufacturing:
ALTER ROLE manufacturing
DROP MEMBER robert;
Summary #
- Use the
ALTER ROLE ... WITH NAMEto rename a role. - Use the
ALTER ROLE ... ADD MEMBERto add a member to role. - Use the
ALTER ROLE ... DROP MEMBERto remove a member from a role.
Thank you for your feedback!