Delen via


CREATE ROLE (Transact-SQL)

Creates a new database role in the current database.

Topic link iconTransact-SQL Syntax Conventions

Syntax

CREATE ROLE role_name [ AUTHORIZATION owner_name ]

Arguments

  • role_name
    Is the name of the role to be created.
  • AUTHORIZATION owner_name
    Is the database user or role that is to own the new role. If no user is specified, the role will be owned by the user that executes CREATE ROLE.

Remarks

Roles are database-level securables. After you create a role, configure the database-level permissions of the role by using GRANT, DENY, and REVOKE. To add members to a database role, use the sp_addrolemember stored procedure. For more information, see Database-Level Roles.

Database roles are visible in the sys.database_role_members and sys.database_principals catalog views.

Warning

In SQL Server 2005 the behavior of schemas is changed from the behavior in earlier versions of SQL Server. Code that assumes that schemas are equivalent to database users may not return correct results. Old catalog views, including sysobjects, should not be used in a database in which any of the following DDL statements has ever been used: CREATE SCHEMA, ALTER SCHEMA, DROP SCHEMA, CREATE USER, ALTER USER, DROP USER, CREATE ROLE, ALTER ROLE, DROP ROLE, CREATE APPROLE, ALTER APPROLE, DROP APPROLE, ALTER AUTHORIZATION. In a database in which any of these statements has ever been used, you must use the new catalog views. The new catalog views take into account the separation of principals and schemas that is introduced in SQL Server 2005. For more information about catalog views, see Catalog Views (Transact-SQL).

Permissions

Requires CREATE ROLE permission on the database. When you use the AUTHORIZATION option, the following permissions are also required:

  • To assign ownership of a role to another user, requires IMPERSONATE permission on that user.
  • To assign ownership of a role to another role, requires membership in the recipient role or ALTER permission on that role.
  • To assign ownership of a role to an application role, requires ALTER permission on the application role.

Examples

A. Creating a database role that is owned by a database user

The following example creates the database role buyers that is owned by user BenMiller.

USE AdventureWorks;
CREATE ROLE buyers AUTHORIZATION BenMiller;
GO

B. Creating a database role called that is owned by a fixed database role

The following example creates the database role auditors that is owned the db_securityadmin fixed database role.

USE AdventureWorks;
CREATE ROLE auditors AUTHORIZATION db_securityadmin;
GO

See Also

Reference

ALTER ROLE (Transact-SQL)
DROP ROLE (Transact-SQL)
EVENTDATA (Transact-SQL)
sp_addrolemember (Transact-SQL)
sys.database_role_members (Transact-SQL)
sys.database_principals (Transact-SQL)

Other Resources

Principals

Help and Information

Getting SQL Server 2005 Assistance