APPX Software Library

Chapter 5: SQL Statements

5.11 GRANT

Description

Grants various privileges to the specified users for the database. There are three forms of the GRANT statement:

  • The first form grants database-wide privileges, either system administration (DBA) or general creation (RESOURCE)
  • The second form grants various privileges on the specified tables or view
  • The third form grants the privilege to execute the specified stored procedure

Syntax

GRANT { RESOURCE, DBA }
    TO user_name [ , user_name ] ... ;

GRANT { privilege [ , privilege ] ... | ALL [ PRIVILEGES ] }
    ON table_name
    TO  { user_name [ , user_name ] ... | PUBLIC }
    [WITH GRANT OPTION] ;

GRANT EXECUTE ON procedure_name
    TO  { user_name [ , user_name ] ... | PUBLIC } ;

privilege ::
    { SELECT | INSERT | DELETE | ALTER | INDEX
            | UPDATE [ (column, column, ... ) ]
            | REFERENCES [ (column, column, ... ) ] }

Arguments

DBA

Allows the specified users to create, access, modify, or delete any database object, and to grant other users any privileges.

RESOURCE

Allows the specified users to issue CREATE statements. The RESOURCE privilege does not allow users to issue DROP statements on database objects. Only the owner of the object and users with the DBA privilege can drop database objects.

ALTER

Allows the specified users to modify the table or view

DELETE

Allows the specified users to delete rows in the table or view

INDEX

Allows the specified users to create an index on the table or view.

INSERT

Allows the specified users to add new rows to the table or view.

SELECT

Allows the specified users to read data in the table or view.

UPDATE [ (column, column, ... ) ]

Allows the specified users to modify existing rows in the table or view. If followed by a column list, the users can modify values only in the columns named.

REFERENCES [ (column, column, ... ) ]

Allows the specified users to refer to the table from other tables’ constraint definitions. If followed by a column list, constraint definitions can refer only to the columns named. For more detail on constraint definitions, see “Table Constraints” and “Column Constraints”.

ALL

Grants all privileges for the table or view.

ON table_name

The table or view for which SQL grants the specified privileges.

EXECUTE ON procedure_name

Allows execution of the specified stored procedure.

TO user_name [ , user_name ] ...

The list of users for which SQL grants the specified privileges.

TO PUBLIC

Grants the specified privileges to any user with access to the system.

WITH GRANT OPTION

Allows the specified users to grant their access rights or a subset of their rights to other users.

Example

GRANT ALTER ON cust_view TO dbuser1 ;
GRANT SELECT ON newcustomers TO dbuser2 ;
GRANT EXECUTE ON sample_proc TO searle;

Authorization

The user granting DBA or RESOURCE privileges must have the DBA privilege.

The user granting privileges on a table must have any of the following privileges:

  • DBA privilege
  • Ownership of the table
  • All the specified privileges on the table, granted with the WITH GRANT OPTION clause
SQL Compliance

SQL-92, ODBC Core SQL grammar. Extensions: ALTER, INDEX, RESOURCE, DBA privileges

Environment

Embedded SQL, interactive SQL, ODBC applications

REVOKE