DCL Commands

In this sub section, let us learn the usage of below commands in detail.

1. GRANT

GRANT statement is used to provide access privileges to users to access the database.

GRANT PRIVILEGES ON DATABASE

Syntax:

GRANT privileges ON DATABASE Database_name TO user/role rolename/PUBLIC [WITH GRANT OPTION];

Let us understand the privileges briefly

PrivilegesDescription
DBADMGrants database administrator authority
DBCTRLGrants database control authority
DBMAINTGrants database maintenance authority
CREATETABGrants the privilege to create new tables
CREATETSGrants the privilege to create new table spaces
DISPLAYDBGrants the privilege to issue the DISPLAY DATABASE command
DROPGrants the privilege to issue the DROP or ALTER DATABASE statements
IMAGCOPYGrants the privilege to run the COPY, MERGECOPY, and QUIESCE utilities and also to run MODIFY RECOVERY utility
LOADGrants the privilege to use the LOAD utility to load tables
RECOVERDBGrants the privilege to use the RECOVER and REPORT utilities to recover table spaces and indexes
REORGGrants the privilege to use the REORG utility to reorganize table spaces and indexes
REPAIRGrants the privilege to use the REPAIR and DIAGNOSE utilities
STARTDBGrants the privilege to issue the START DATABASE command
STATSGrants the privilege to use the RUNSTATS utility to update statistics
STOPDBGrants the privilege to issue the STOP DATABASE command

Example

With this command, all the local users can execute the DISPLAY database command

   GRANT DISPLAYDB ON DATABASE DSN8D143A  TO PUBLIC;

GRANT PRIVILEGES ON Tables and Views

Syntax

GRANT privileges ON TABLE Table_name TO user/role rolename/PUBLIC [WITH GRANT OPTION];

Let us understand the privileges briefly

PrivilegesDescription
ALL or ALL PRIVILEGESGrants all table or view privileges
ALTERGrants the privilege to alter the specified table
DELETEGrants the privilege to delete rows in the specified table or view
INDEXGrants the privilege to create an index on the specified table
INSERTGrants the privilege to insert rows into the specified table or view
REFERENCES (Column_name)Grants the privilege to add or drop a referential constraint in which the specified table is a parent using only those columns that are specified in the column list as a parent key
SELECTGrants the privilege to create a view or read data from the specified table or view
TRIGGERGrants the privilege to create a trigger on the specified table
UPDATEGrants the privilege to update rows in the specified table or view.

2. REVOKE

REVOKE statement is used to withdraw the access priviliges given to a user by GRANT statement.

REVOKE PRIVILEGES ON DATABASE

Syntax:

REVOKE privileges ON DATABASE Database_name FROM user/role rolename/PUBLIC BY user/role rolename/ALL;

Let us understand the privileges briefly

PrivilegesDescription
DBADMRevokes the database administrator authority
DBCTRLRevokes the database control authority
DBMAINTRevokes the database maintenance authority
CREATETABRevokes the privilege to create new tables
CREATETSRevokes the privilege to create new table spaces
DISPLAYDBRevokes the the privilege to issue the DISPLAY DATABASE command
DROPRevokes the the privilege to issue the DROP or ALTER DATABASE statements
IMAGCOPYRevokes the the privilege to run the COPY, MERGECOPY, and QUIESCE utilities and also to run MODIFY RECOVERY utility
LOADRevokes the privilege to use the LOAD utility to load tables
RECOVERDBRevokes the privilege to use the RECOVER and REPORT utilities to recover table spaces and indexes
REORGRevokes the privilege to use the REORG utility to reorganize table spaces and indexes
REPAIRRevokes the privilege to use the REPAIR and DIAGNOSE utilities
STARTDBRevokes the privilege to issue the START DATABASE command
STATSRevokes the privilege to use the RUNSTATS utility to update statistics
STOPDBRevokes the privilege to issue the STOP DATABASE command

Example

With this command, DISPLAY database command execution authorization will be revoked from all local users.

   REVOKE DISPLAYDB ON DATABASE DSN8D143A  FROM PUBLIC;

REVOKE PRIVILEGES ON Tables and Views

Syntax

REVOKE privileges ON TABLE Table_name FROM user/role rolename/PUBLIC BY user/role rolename/ALL;

Let us understand the privileges briefly

PrivilegesDescription
ALL or ALL PRIVILEGESRevokes all table or view privileges
ALTERRevokes the privilege to alter the specified table
DELETERevokes the privilege to delete rows in the specified table or view
INDEXRevokes the privilege to create an index on the specified table
INSERTRevokes the privilege to insert rows into the specified table or view
REFERENCES (Column_name)Revokes the privilege to add or drop a referential constraint in which the specified table is a parent using only those columns that are specified in the column list as a parent key
SELECTRevokes the privilege to create a view or read data from the specified table or view
TRIGGERRevokes the privilege to create a trigger on the specified table
UPDATERevokes the privilege to update rows in the specified table or view.