ALTER ROLE (Transact-SQL)

**APPLIES TO:** ![yes](media/yes.png)SQL Server (starting with 2008) ![yes](media/yes.png)Azure SQL Database ![yes](media/yes.png)Azure SQL Data Warehouse ![yes](media/yes.png)Parallel Data Warehouse

Adds or removes members to or from a database role, or changes the name of a user-defined database role.

[!NOTE]
To alter roles adding or dropping members in SQL Data Warehouse or SQL Data Warehouse Parallel Data Warehouse use sp_addrolemember (Transact-SQL) and sp_droprolemember (Transact-SQL).

Topic link icon Transact-SQL Syntax Conventions

Syntax

-- Syntax for SQL Server (starting with 2012) and Azure SQL Database  
  
ALTER ROLE  role_name  
{  
       ADD MEMBER database_principal  
    |  DROP MEMBER database_principal  
    |  WITH NAME = new_name  
}  
[;]  
-- Syntax for SQL Server 2008, Azure SQL Data Warehouse and Parallel Data Warehouse
  
-- Change the name of a user-defined database role  
ALTER ROLE role_name   
    WITH NAME = new_name  
[;]  

Arguments

role_name
APPLIES TO: SQL Server (starting with 2008), SQL Server Azure SQL Database

Specifies the database role to change.

ADD MEMBER database_principall
APPLIES TO: SQL Server (starting with 2012), SQL Server Azure SQL Database

Specifies to add the database principal to the membership of a database role.

DROP MEMBER database_principal
APPLIES TO: SQL Server (starting with 2012), SQL Server Azure SQL Database

Specifies to remove a database principal from the membership of a database role.

WITH NAME = new_name
APPLIES TO: SQL Server (starting with 2008), SQL Server Azure SQL Database

Specifies to change the name of a user-defined database role. The new name must not already exist in the database.

Changing the name of a database role does not change ID number, owner, or permissions of the role.

Permissions

To run this command you need one or more of these permissions or memberships:

Additionally, to change the membership in a fixed database role you need:

Limitations and restrictions

You cannot change the name of a fixed database role.

Metadata

These system views contain information about database roles and database principals.

Examples

A. Change the name of a database role

APPLIES TO: SQL Server (starting with 2008), SQL Server SQL Database

The following example changes the name of role buyers to purchasing. This example can be executed in the AdventureWorks sample database.

ALTER ROLE buyers WITH NAME = purchasing;  

B. Add or remove role members

APPLIES TO: SQL Server (starting with 2012), SQL Server SQL Database

This example creates a database role named Sales. It adds a database user named Barry to the membership, and then shows how to remove the member Barry. This example can be executed in the AdventureWorks sample database.

CREATE ROLE Sales;  
ALTER ROLE Sales ADD MEMBER Barry;  
ALTER ROLE Sales DROP MEMBER Barry;  

See Also

CREATE ROLE (Transact-SQL)
Principals (Database Engine)
DROP ROLE (Transact-SQL)
sp_addrolemember (Transact-SQL)
sys.database_role_members (Transact-SQL)
sys.database_principals (Transact-SQL)