A154_Exp9
A154_Exp9
PART A
(Part A: TO BE REFERRED BY STUDENTS)
Experiment No. 09
A.1 AIM:
To study and understand Transaction Control Language (TCL) using commands like Commit,
Rollback and create save point and use it with Rollback.
To study Data Control Language (DCL) using commands like GRANT and REVOKE
A.3 Outcome:
After successful completion of this experiment students will be able to
A.4 Theory:
Transaction:
A transaction is a logical unit of work that contains one or more SQL statements. A
transaction is an atomic unit. The effects of all the SQL statements in a transaction can be
either all committed (applied to the database) or all rolled back (undo from the database).
A transaction begins with the first executable SQL statement. A transaction ends when it is
committed or rolled back, either explicitly with a COMMIT or ROLLBACK statement or
implicitly when a DDL statement is issued.
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering (Mumbai Campus)
Computer Engineering Department (B Tech CSE/CSBS Sem IV/BTI Sem
VIII/MBA.Tech-IV)
Database Management System
Lab Manual
Transactional control commands are only used with the DML commands INSERT, UPDATE
and DELETE only. They cannot be used while creating tables or dropping them because these
operations are automatically committed in the database.
1. COMMIT Command:
The COMMIT command is the transaction control command used to save changes invoked by a
transaction to the database.
The COMMIT command saves all transactions to the database since the last COMMIT or
ROLLBACK command.
Example:
SQL> COMMIT;
The ROLLBACK command is the transactional command used to undo transactions that have
not already been saved to the database.
The ROLLBACK command can only be used to undo transactions since the last COMMIT or
ROLLBACK command was issued.
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering (Mumbai Campus)
Computer Engineering Department (B Tech CSE/CSBS Sem IV/BTI Sem
VIII/MBA.Tech-IV)
Database Management System
Lab Manual
ROLLBACK;
For example
SQL> ROLLBACK;
SAVEPOINT SAVEPOINT_NAME;
This command serves only in the creation of a SAVEPOINT among transactional statements.
The ROLLBACK command is used to undo a group of transactions.
SQL> SAVEPOINT
ROLLBACK SP1;
TO SAVEPOINT_NAME;
Savepoint created.
Example:
SQL> DELETE FROM CUSTOMERS WHERE ID=1;
1 row deleted.
1 row deleted.
Savepoint created.
1 row deleted.
Rollback complete.
DCL includes commands such as GRANT and REVOKE which mainly deal
with the rights, permissions, and other controls of the database system.
PART B
(PART B: TO BE COMPLETED BY STUDENTS)
(Students must submit the soft copy as per following segments within two hours of the practical.
The soft copy must be uploaded on the Blackboard or emailed to the concerned lab in charge
faculties at the end of the practical in case the there is no Black board access available)
SQL Queries:
-- Creating table
Name VARCHAR(50),
Marks INT
);
-- Inserting records
SAVEPOINT A;
SAVEPOINT B;
SAVEPOINT C;
ROLLBACK TO B;
COMMIT;
DCL Commands:
-- Granting privileges
-- Revoking privileges
B.2 Conclusion:
Output (Expected):
• Savepoint A created.
In this experiment, I learned how Transaction Control Language (TCL) commands like
COMMIT, ROLLBACK, and SAVEPOINT are used to manage data consistency in SQL
databases. I also understood the concept of Data Control Language (DCL), which is used to
assign and remove privileges for database users. These commands are crucial in multi-user
environments to ensure secure and reliable data operations.
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering (Mumbai Campus)
Computer Engineering Department (B Tech CSE/CSBS Sem IV/BTI Sem
VIII/MBA.Tech-IV)
Database Management System
Lab Manual
1. What is a transaction?
A transaction is a logical unit of work that consists of one or more SQL operations. It ensures
data consistency and is either fully completed or fully rolled back.
Example:
3. What was your observation about savepoint command? Explain with an example.
SAVEPOINT allows setting a point within a transaction to which you can roll back without
affecting all changes.
Example:
SAVEPOINT A;
ROLLBACK TO A; -- Reverts only the last update, keeping earlier operations intact
DCL commands like GRANT and REVOKE help manage database security by giving or
restricting access to users. In a multi-user setup, this prevents unauthorized access and ensures
each user has only the permissions they need.