Granting a Permission
Function
This statement is used to grant permissions to a user or role.
Syntax
1 | GRANT (privilege,...) ON (resource,..) TO ((ROLE [db_name].role_name) | (USER user_name)),...);
|
Keyword
ROLE: The subsequent role_name must be a role.
USER: The subsequent user_name must be a user.
Precautions
- The privilege must be one of the authorizable permissions. If the object has the corresponding permission on the resource or the upper-level resource, the permission fails to be granted. For details about the permission types supported by the privilege, see Data Permissions List.
- The resource can be a queue, database, table, view, or column. The formats are as follows:
- Queue format: queues.queue_name
- Database format: databases.db_name
- Table format: databases.db_name.tables.table_name
- View format: databases.db_name.tables.view_name
- Column format: databases.db_name.tables.table_name.columns.column_name
Example
Run the following statement to grant user_name1 the permission to delete the db1 database:
1 | GRANT DROP_DATABASE ON databases.db1 TO USER user_name1;
|
Run the following statement to grant user_name1 the SELECT permission of data table tb1 in the db1 database:
1 | GRANT SELECT ON databases.db1.tables.tb1 TO USER user_name1;
|
Run the following statement to grant role_name the SELECT permission of data table tb1 in the db1 database:
1 | GRANT SELECT ON databases.db1.tables.tb1 TO ROLE role_name;
|
Last Article: Displaying a Role
Next Article: Revoking a Permission
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.