CREATE DATABASE ROLE¶
Create a new database role or replace an existing database role in the system.
After creating database roles, you can grant object privileges to the database role and then grant the database role to other database roles or account roles to enable access control security for objects in the system.
This command supports the following variants:
CREATE OR ALTER DATABASE ROLE: Creates a new database role if it doesn’t exist or alters an existing database role.
Tip
You can also use the Snowflake REST APIs to perform this operation. For information, see Create a database role (REST endpoint reference).
- See also:
GRANT <privileges>, GRANT DATABASE ROLE , GRANT OWNERSHIP , DROP DATABASE ROLE , ALTER DATABASE ROLE , SHOW DATABASE ROLES, CREATE <object> … CLONE, CREATE OR ALTER <object>
Syntax¶
CREATE [ OR REPLACE ] DATABASE ROLE [ IF NOT EXISTS ] <name>
[ COMMENT = '<string_literal>' ]
Variant syntax¶
CREATE OR ALTER DATABASE ROLE¶
Creates a new database role if it doesn’t already exist, or transforms an existing database role into the role defined in the statement. A CREATE OR ALTER DATABASE ROLE statement follows the syntax rules of a CREATE DATABASE ROLE statement and has the same limitations as an ALTER DATABASE ROLE statement.
CREATE OR ALTER DATABASE ROLE <name>
[ COMMENT = '<string_literal>' ]
For more information, see CREATE OR ALTER DATABASE ROLE usage notes.
Required parameters¶
name
Specifies the identifier (i.e. name) for the database role; must be unique in the database in which the role is created.
The identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (e.g.
"My object"
). Identifiers enclosed in double quotes are also case-sensitive.If the identifier is not fully qualified in the form of
db_name.database_role_name
, the command creates the database role in the current database for the session.For more details, see Identifier requirements.
Optional parameters¶
COMMENT = 'string_literal'
Specifies a comment for the database role.
Default: No value
Access control requirements¶
A role used to execute this SQL command must have the following privileges at a minimum:
Privilege |
Object |
Notes |
---|---|---|
CREATE DATABASE ROLE |
Database |
A role with the OWNERSHIP privilege on the database can grant the CREATE DATABASE ROLE privilege to another account role. |
OWNERSHIP |
Database role |
Required to execute a CREATE OR ALTER DATABASE ROLE statement for an existing database role. OWNERSHIP is a special privilege on an object that is automatically granted to the role that created the object, but can also be transferred using the GRANT OWNERSHIP command to a different role by the owning role (or any role with the MANAGE GRANTS privilege). |
For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.
For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.
General usage notes¶
When you create a database role, the USAGE privilege on the database that contains the database role is granted to the database role automatically.
Caution
Avoid recreating a database role (using the OR REPLACE keywords). Behind the scenes, recreating an object (using CREATE OR REPLACE <object>) first drops and then creates the object. Recreating a database role drops the database role from any shares that it is granted to. You must grant the database role to these shares again.
If you must recreate a database role, notify any data consumers of a share that includes the database role. They must grant the database role to their own account roles again.
Regarding metadata:
Attention
Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.
CREATE OR ALTER DATABASE ROLE usage notes¶
All limitations of the ALTER DATABASE ROLE command apply.
Setting or unsetting a tag is not supported; however, existing tags are not altered by a CREATE OR ALTER DATABASE ROLE statement and remain unchanged.
Examples¶
Create database role dr1
in database d1
:
CREATE DATABASE ROLE d1.dr1;