Assigns permissions to individual users, groups of users, and roles.
grant {all [privileges] | permission_list} on {table_name as [correlation_name][(column_list)] | view_name[(column_list)] | stored_procedure_name | SQL_function_name} | keyname} [where search_conditions [as pred_name]] to {public | name_list | role_list} [with grant option] [granted by grantor]
grant select on [builtin] builtin to {name_list | role_list} [granted by grantor]
grant {all [privileges] | privilege_list} to {public | name_list | role_list} [granted by grantor]
grant {dbcc_privilege [on database ] [, dbcc_privilege [on database ], ...]} to {user_list | role_list } [granted by grantor]
grant default permissions on system tables
grant set proxy to name_list [restrict role role_list | all | system] [granted by grantor]
When granular permissions is not enabled, a system administrator or the database owner can use grant all to assign privileges to create database objects (see syntax for “Grants system privileges to execute certain commands”). When used by a system administrator, grant all assigns all create privileges (create database, create default, create procedure, create rule, create table, create function, and create view). When the database owner uses grant all , or executes grant all outside the master database, the SAP ASE server grants all create privileges except create database and prints an informational message.
Granting all create privileges using grant all is not supported when granular permissions is enabled. For more information, see Using Granular Permissions in the Security Administration Guide.
all cannot be used for a grant statement that includes a where clause.
Object |
permission_list Can Include |
---|---|
Column |
select, update, references, decrypt Column names can be specified in column_list. |
Encryption key |
select |
Stored procedure |
execute |
SQL function |
execute |
Table |
select, insert, delete, update, references, update statistics, delete statistics, truncate table, decrypt, transfer table, identity_insert *, identity_update * |
View |
select, insert, delete, update, decrypt, identity_insert *, identity_update * |
When the grant is made on one or more named columns using a where clause, then the SAP ASE server enforces row-level access on the user's select, update or delete command as follows:
one or more of the named columns on a grant select statement is referenced in the target list or where clause of the user's select statement
one or more of the named columns on a grant update statement is referenced in the target list of the user's update statement
one or more columns on a grant select is referenced in the where clause of the user's update or delete statement where the session has set ansi_permissions on.
If there are multiple granted actions in the same command, database must be unique.
grant insert, delete on titles to mary, sales
grant select on builtin get_appcontext to public
grant select on get_appcontext to public
Specifically including the builtin argument in your grant statement ensures that you do not mistakenly select a table that has the same name as a function—in this example, the get_appcontext function versus a table called get_appcontext.
grant update on titles (price, advance) to public
grant update (price, advance) on titles to public
grant transfer table on titles to mary
grant create database, create table to mary, john
grant all on titles to public
grant update on authors to mary with grant option
grant select, update on titles (price) to bob with grant option
grant execute on new_sproc to sso_role
grant references on titles (price) to james
grant select on ssn_key to dbo
grant create encyption key to Bob
grant decrypt on customer to accounts_role
1> use master 2> go 1> grant dump any database to joe 2> go
1> use pubs2 2> go 1> grant create any object to joe 2> go
1> use pubs2 2> go 1> grant manage roles to alex 2> go
Msg 4627, Level 16, State 1: Line 1: The user must be in the master database to GRANT/REVOKE this command.
1> use master 2> go 1> create role checkalloc_role 2> go 1> grant dbcc checkalloc any database to checkalloc_role 2> go 1> create login carlos with password carlospassword 2> go 1> grant role checkalloc_role to carlos 2> go
1> use master 2> go 1> create login frank with password frankpassword 2> go
Password correctly set. Account unlocked. New login created. (return status = 0)
1> sp_adduser frank 2> go
New user added. (return status = 0)
1> grant dbcc checkdb any database to frank 2> go
% isql -Ufrank -Pfrankpassword -SSERVER 1> dbcc checkdb (tempdb) 2> go
Checking tempdb: Logical pagesize is 2048 bytes Checking sysobjects: Logical pagesize is 2048 bytes ... The total number of data pages in this table is 1. DBCC execution completed. If DBCC printed error messages, contact a user with system administrator (SA) role.
1> use pubs2 2> go 1> grant dbcc checkdb on pubs2 to walter 2> go
Walter can now execute the dbcc checkdb command on the customers database without encountering an error.
1> grant dbcc tablealloc on pubs2 to public
Msg 4629, Level 16, State 1: Line 1: GRANT/REVOKE DBCC does not apply to groups or PUBLIC.
1> sp_addgroup gr
New group added. (return status = 0)
1> grant dbcc tablealloc on pubs2 to gr
Msg 4629, Level 16, State 1: Line 1: GRANT/REVOKE DBCC does not apply to groups or PUBLIC.
grant change password to alex with grant option
Msg 156, Level 15, State 1: Line 1: Incorrect syntax near the keyword 'with'.
grant truncate table on authors to harry grant update statistics on authors to harry
grant delete statistics on authors to billy
grant truncate table on authors to oper_role grant update statistics on authors to oper_role grant delete statistics on authors to oper_role
create procedure sproc1 as truncate table authors update statistics authors go grant execute on sproc1 to harry go
You can also implicitly grant permissions at the column level for update statistics and delete statistics through stored procedures.
grant set proxy to harry, billy
grant set session authorization to sso_role
grant set proxy to joe restrict role sa_role, sso_role, admin_role
set proxy Our_admin_role
Msg 10368, Level 14, State 1: Server 's', Line 2:Set session authorization permission denied because the target login has a role that you do not have and you have been restricted from using.
grant role admin_role to joe set proxy Our_admin_role
grant set proxy to joe restrict role all
Joe can set proxy only to those users who have the same roles (or roles with fewer privileges) than he has.
grant set proxy to joe restrict role system
set proxy fails if the target login has system roles that Joe lacks.
grant select on grades where user_name(uid) = USER as predicate_grades to public
grant select on enrollment (course_id, quarter, section_id) to public grant select on enrollment as e (uid, with_honors) where e.uid in (select r.uid from registered_students r where USER = user_name(r.uid)) to public
select course_id, quarter, with_honors from enrollment
select course_id, count(uid) from enrollment group by course_idThe SAP ASE server returns one row giving the count of courses enrolled in by the user.
grant select on mary.books to john granted by mary
grant create table to john granted by dbo
1>sp_configure "enable granular permissions" 2>goParameter Name Default Memory Used Config Value Run Value Unit Type -------------- ------- ---------- ------------ --------- ---- ---- enable granular permissions 0 0 0 0 switch dynamic (1 row affected) (return status = 0) >grant manage any login to smith >go Msg 16325, Level 15, State 87: Line 1: Cannot GRANT/REVOKE permission 'MANAGE ANY LOGIN'. Verify that the granular permissions option is enabled.
1>grant own database to smith 2>goMsg 156, Level 15, State 2: Line 1: Incorrect syntax near the keyword 'to'. 1>grant own database on tdb1 to smith 2>go
You can substitute the word from for to in the grant syntax.
SQL statement on line number 1 contains Non-ANSI text. The error is caused due to the use of DBCC.
Revoking a specific permission from “public” or from a group also revokes it from users who were individually granted the permission. An exeption are grants and revokes of predicated privileges.
grant fails if you attempt to grant permissions to user-defined roles in a local temporary database in shared-disk cluster.
proc_role, show_role in Reference Manual: Building Blocks
sp_column_privileges, sp_table_privileges, sp_addgroup, sp_adduser, sp_changedbowner, sp_changegroup, sp_dropgroup, sp_dropuser, sp_helpgroup, sp_helprotect, sp_helpuser in Reference Manual: Procedures
For more information on revoking a privilege from public or a group, see How SAP ASE Saves Predicated Privileges in sysprotects in the Security Administration Guide
ANSI SQL – Compliance level: Entry-level compliant. grant dbcc is also a Transact-SQL extension.
grant dbcc, and granting permissions to groups and granting set proxy are Transact-SQL extensions. Granting set session authorization (identical in function to set proxy) follows the ANSI standard.
The permission checks for grant differ based on your granular permissions settings.
Setting | Description |
---|---|
Enabled | With granular permissions enabled, in general, grant can be executed
by a user with one of the following privilege management privileges, depending the privilege
or permission being granted. For:
|
Disabled | With granular permissions disabled, grantable system privileges are limited to create database, create default, create function, create procedure, create rule, create table, create view, connect, set proxy, and set tracing Command execution – only system administrators can grant create database, connect, and set tracing permissions, and only from the master database. Only system security officers can grant create trigger permission. To execute grant default, you must be the database owner or a user with sa_role. For:
|
Values in event and extrainfo columns of sysaudits are:
Information | Values |
---|---|
Event | 40 |
Audit option | grant |
Command or access audited | grant |
Information in extrainfo |
|