Introduction To Transaction Control Language
Introduction To Transaction Control Language
Language
In a Relational Database Management System (RDBMS), the Structured
retrieve and manipulate the data across various tables in a database. Let
mistakenly and want to restore the data or we have inserted few records
and want to save them, there Transaction Control Language (TCL) comes
which are made by the DML operations. The alteration made by the DML
these changes can be canceled before the present session gets closed.
consistent state. The Transactions are used on all the DDL and DML
queries automatically.
the individual DML commands are executed, they become the part of the
transaction and when the logical procedure is over, the transaction gets
committed. The commit command ensures that the changes are made
and Savepoint.
1. COMMIT
This command is used to make a transaction permanent in a database.
So it can be said that commit command saves the work done as it ends
COMMIT;
Query:
above and the usage of the above statements will update the location of
the employee ‘Raju’ and the change will be saved in the database
permanently.
2. ROLLBACK
This command is used to restore the database to its original state since
the last command that was committed. The syntax of the Rollback
command is as below:
ROLLBACK;
leap to a save point in a transaction. The syntax for the same is as below:
ROLLBACK TO <savepoint_name>;
Let us take the example of the EMPLOYEE table as cited above. Let us
consider that we have updated EMP_LOC for Raju to Bangalore later and
realize that the update was done mistakenly as below. Then we can
restore the EMP_LOC for ‘Raju’ to Hyderabad again by using the Rollback
command as below.
Query:
After the Rollback is performed, the location for Raju is restored to the
3. SAVEPOINT
This command is used to save the transaction temporarily. So the users
can rollback to the required point of the transaction. The syntax for using
SAVEPOINT savepoint_name;
and ITEM_NAME.
ORDER_ID ITEM_NAME
199 TELEVISION
290 CAMERA
Let us insert the below values to the ORDERS table below and perform
Query:
ORDER_ID ITEM_NAME
199 TELEVISION
290 CAMERA
566 BLENDER
Now we can use the SAVEPOINT command to Rollback the transaction.
Query:
ROLLBACK TO A;
ORDER_ID ITEM_NAME
199 TELEVISION
290 CAMERA
permanent change to the database by locking the data using the commit
command. Also with the help of savepoint command, users can save the
the savepoint.
Conclusion
Transaction Control Language helps in maintaining the consistency and
integrity of the data. The database can be restored to the last committed