Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
13 views

TCL Commands in SQL o in SQL

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

TCL Commands in SQL o in SQL

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

* TCL Commands in SQL o In SQL, TCL stands for Transaction control language.

o A single unit of work in


a database is formed after the consecutive execution of commands is known as a transaction. o There
are certain commands present in SQL known as TCL commands that help the user manage the
transactions that take place in a database. o COMMIT. ROLLBACK and SAVEPOINT are the most
commonly used TCL commands 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.

Syntax: 1. SAVEPOINT savepoint_name;

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

. Syntax: 1. ROLLBACK TO savepoint_name;

You might also like