Experiment 8 Dbms-1
Experiment 8 Dbms-1
Theory:
DCL:
DCL (Data Control Language) commands are used to control access to a database. These commands
are used to grant or revoke privileges to users and roles in a database.
• Security:
• Syntax:
ON <table-name> to <USER|PUBLIC>
• Syntax:
A Transaction is a set of SQL statements that are executed on the data stored in DBMS.
Whenever any transaction is made these transactions are temporarily happen in database. So to
make the changes permanent, we use TCL commands.
The TCL commands are:
1. COMMIT
2. ROLLBACK
3. SAVEPOINT
1. COMMIT:
This command is used to save the data permanently.
Whenever we perform any of the DML command like -INSERT, DELETE or UPDATE, these can
be rollback if the data is not stored permanently. So in order to be at the safer side COMMIT
command is used.
Syntax: commit;
2. ROLLBACK :
This command is used to get the data or restore the data to the last savepoint or last committed
state. If due to some reasons the data inserted, deleted or updated is not correct, you can rollback
the data to a particular savepoint or if savepoint is not done, then to the last committed state.
Syntax: rollback;
3. SAVEPOINT:
This command is used to save the data at a particular point temporarily, so that whenever needed
can be rollback to that particular point.
Syntax:
Savepoint A;
Application of DCL & TCL Commands:
REVOKE :
Example :
TCL:
1. COMMIT:
Example:
Consider the following Table Student:
UPDATE medical_students
SET name = 'Aniket'
WHERE name = 'Alexa';
COMMIT;
ROLLBACK;
By using this command you can update the record and save it permanently by
using COMMIT command.
If commit was not performed then the changes made by the update command can be rollback.
Now if no COMMIT is performed.
UPDATE medical_students
SET name = 'Sakshi'
WHERE name = 'Nikhil';
After update command the table will be:
Now if ROLLBACK is performed on the above table
rollback;
After Rollback:
UPDATE medical_students
SET name = 'Alexander'
WHERE marks = 79;
SAVEPOINT A;
INSERT INTO medical_students (id, name, marks) VALUES (5, 'Zack', 76);
Savepoint B;
INSERT INTO medical_students (id, name, marks) VALUES (2, 'Zack', 76);
Savepoint C;
SELECT * FROM STUDENT;
So It was all about TCL commands in SQL (transaction control language) with examples.