Tuesday, 19 July 2016

Data Control Language

We have discussed about  DDL ,  DML and DQL and TCL commands earlier now lets checkout DCL.

DCL commands are used to granting and revoking the permissions.
It has 2 commands i.e. Grant and Revoke.

1.5 Data Control Language
1) GRANT

This is used to grant the privileges to other users.

Syntax:
Grant <privileges> on <object_name> to <user_name> [with grant option];

Ex:
SQL> grant select on student to Venky; — you can give individual privilege
SQL> grant select, insert on student to Venky; — you can give set of privileges
SQL> grant all on student to Venky; — you can give all privileges

The Venky user has to use dot method to access the object .

SQL> select * from Ram.student;

here i have mentioned ram.student because student table is own table of venky user, venky user got permission from RAM user to use this so i need to
specify ram username before object/table name.

The Venky user can not grant permission on student table to other users. To get this type of option use the following.

SQL> grant all on student to Venky with grant option;

Now Venky users also grant permissions on student table.

2) REVOKE

This is used to revoke the privileges from the users to which you granted the privileges.

Syntax: Revoke <privileges> on <object_name> from <user_name>;

Ex:
SQL> revoke select on student form Venky; — you can revoke individual privilege
SQL> revoke select, insert on student from Venky; — you can revoke set of privileges
SQL> revoke all on student from Venky; — you can revoke all privileges.

No comments:

Post a Comment