DCL in SQL
DCL in SQL
Two types of DCL commands are GRANT and REVOKE. Only Database Administrators or owners of
the database object can provide/remove privileges on a database object.
REVOKE privilege_name
ON object_name
FROM {user_name |PUBLIC |role_name}
For Eample: REVOKE SELECT ON employee FROM user1;This commmand will REVOKE a SELECT
privilege on employee table from user1.When you REVOKE SELECT privilege on a table from a user,
the user will not be able to SELECT data from that table anymore. However, if the user has
received SELECT privileges on that table from more than one users, he/she can SELECT from that
table until everyone who granted the permission revokes it. You cannot REVOKE privileges if they
were not initially granted by you.
System
Description
Privileges
allows users to create the specified object in
CREATE object
their own schema.
CREATE ANY allows users to create the specified object in
object any schema.
The above rules also apply for ALTER and DROP system privileges.
Object
Description
Privileges
INSERT allows users to insert rows into a table.
allows users to select data from a database
SELECT
object.
UPDATE allows user to update data in a table.
allows user to execute a stored procedure or
EXECUTE
a function.
Roles: Roles are a collection of privileges or access rights. When there are many users in a
database it becomes difficult to grant or revoke privileges to users. Therefore, if you define roles,
you can grant or revoke privileges to users, thereby automatically granting or revoking privileges.
You can either create Roles or use the system roles pre-defined by oracle.
Some of the privileges granted to the system roles are as given below:
System
Privileges Granted to the Role
Role
CREATE TABLE, CREATE VIEW, CREATE
CONNECT SYNONYM, CREATE SEQUENCE, CREATE
SESSION etc.
CREATE PROCEDURE, CREATE SEQUENCE,
CREATE TABLE, CREATE TRIGGER etc. The
RESOURCE
primary usage of the RESOURCE role is to
restrict access to database objects.
DBA ALL SYSTEM PRIVILEGES
Creating Roles:
The Syntax to create a role is:
CREATE ROLE role_name
[IDENTIFIED BY password];
For example: To create a role called "developer" with password as "pwd",the code will be as
follows
CREATE ROLE testing
[IDENTIFIED BY pwd];
It's easier to GRANT or REVOKE privileges to the users through a role rather than assigning a
privilege direclty to every user. If a role is identified by a password, then, when you GRANT or
REVOKE privileges to the role, you definetely have to identify it with the password.
For example: To grant CREATE TABLE privilege to a user by creating a testing role:
Second, grant a CREATE TABLE privilege to the ROLE testing. You can add more privileges to the
ROLE.
To revoke a CREATE TABLE privilege from testing ROLE, you can write: