TCL Commands in SQL o in SQL
TCL Commands in SQL o in SQL
1. COMMIT
COMMIT command in SQL is used to save all the transaction-related changes permanently to
the disk. Whenever DDL commands such as INSERT, UPDATE and DELETE are used, the changes
made by these commands are permanent only after closing the current session. So before
closing the session, one can easily roll back the changes made by the DDL commands. Hence, if
we want the changes to be saved permanently to the disk without closing the session, we will
use the commit command.
Syntax: 1. COMMIT;
2. SAVEPOINT
We can divide the database operations into parts. For example, we can consider all the insert
related queries that we will execute consecutively as one part of the transaction and the delete
command as the other part of the transaction. Using the SAVEPOINT command in SQL, we can
save these different parts of the same transaction using different names. For example, we can
save all the insert related queries with the savepoint named INS. To save all the insert related
queries in one savepoint, we have to execute the SAVEPOINT query followed by the savepoint
name after finishing the insert command execution.
3. ROLLBACK
While carrying a transaction, we must create savepoints to save different parts of the
transaction. According to the user's changing requirements, he/she can roll back the transaction
to different savepoints. Consider a scenario: We have initiated a transaction followed by the
table creation and record insertion into the table. After inserting records, we have created a
savepoint INS. Then we executed a delete query, but later we thought that mistakenly we had
removed the useful record. Therefore in such situations, we have an option of rolling back our
transaction. In this case, we have to roll back our transaction using the ROLLBACK command to
the savepoint INS, which we have created before executing the DELETE query