DBMS Exp 6
DBMS Exp 6
THEORY:
DCL commands manage permissions and access control in SQL databases. The two main DCL
commands are GRANT and REVOKE.
1.GRANT:
Definition: Provides privileges to users.
Syntax:
grant privilege_name on object_name to user_name;
Example:
grant select, insert on employees to John;
Explanation:
This grants SELECT and INSERT privileges on the employees table to the user John.
2.REVOKE:
Definition: Removes privileges from users.
Syntax:
revoke privilege_name on object_name from user_name;
Example:
revoke insert on employees from John;
Explanation:
This revokes the INSERT privilege on the employees table from the user John
Transaction Control Language (TCL)
TCL commands handle transactions in a database. Common TCL commands include
COMMIT, ROLLBACK, and SAVEPOINT.
1.COMMIT:
Definition: Saves all changes made in the current transaction.
Syntax:
commit;
Example:
update students set grade = 'A' where student_id = 1;
commit;
Explanation:
This updates the grade of the student with student_id = 1 to 'A' and saves the change
permanently.
ROLLBACK: Undoes all changes made in the current transaction before the COMMIT.
Syntax:
rollback;
Example:
delete from students where student_id = 2;
rollback;
Explanation:
This deletes the student with student_id = 2, but the ROLLBACK undoes the deletion.
SAVEPOINT: Creates a point in the transaction to which you can later roll back.
Syntax:
savepoint savepoint_name;
Example:
update students set grade = 'B' where student_id = 3;
savepoint sp1;
update students set grade = 'C' where student_id = 4;
rollback to sp1;
Explanation:
This updates the grade of the student with student_id = 3 to 'B', sets a savepoint, and then
updates the grade of the student with student_id = 4 to 'C'. The rollback undoes the change
made to student_id = 4, but keeps the change for student_id = 3.
Create a user:
Create a role:
Rollback:
Create savepoints:
Rollback to a savepoint:
CONCLUSION:
In this experiment, we used DCL commands like GRANT and REVOKE to manage user
permissions, and TCL commands such as COMMIT, ROLLBACK, and SAVEPOINT to control
transactions. These commands help manage database security and ensure changes can be
saved or undone as needed.