-
Transaction Control Language
can be defined as the portion of a database language used formaintaining consistency
of the database andmanaging transactions
in the database. -
A set of
SQL statements
that areco-related logically and executed on the data stored in the table
is known as atransaction
.
COMMIT
CommandROLLBACK
CommandSAVEPOINT
Command
The main use of COMMIT
command is to make the transaction permanent
. If there is a need for any transaction to be done in the database that transaction permanent through commit command.
COMMIT;
Using this command, the database can be restored to the last committed state
. Additionally, it is also used with savepoint command for jumping to a savepoint in a transaction.
ROLLBACK TO savepoint-name;
The main use of the Savepoint command is to save a transaction temporarily. This way users can rollback to the point whenever it is needed.
SAVEPOINT savepoint-name;
item | price | customer_name |
---|---|---|
Pen | 10 | Sanskriti |
Bag | 1000 | Sanskriti |
Vegetables | 500 | Sanskriti |
Shoes | 5000 | Sanskriti |
Water Bottle | 800 | XYZ |
Mouse | 120 | ABC |
Sun Glasses | 1350 | ABC |
UPDATE purchase SET price = 20 WHERE item = "Pen";
SELECT * FROM purchase;
item | price | customer_name |
---|---|---|
Pen | 20 | Sanskriti |
Bag | 1000 | Sanskriti |
Vegetables | 500 | Sanskriti |
Shoes | 5000 | Sanskriti |
Water Bottle | 800 | XYZ |
Mouse | 120 | ABC |
Sun Glasses | 1350 | ABC |
START TRANSACTION;
COMMIT;
ROLLBACK;
SELECT * FROM purchase;
item | price | customer_name |
---|---|---|
Pen | 20 | Sanskriti |
Bag | 1000 | Sanskriti |
Vegetables | 500 | Sanskriti |
Shoes | 5000 | Sanskriti |
Water Bottle | 800 | XYZ |
Mouse | 120 | ABC |
Sun Glasses | 1350 | ABC |
SAVEPOINT sv_update;
UPDATE purchase SET price = 30 WHERE item = "Pen";
SELECT * FROM purchase;
item | price | customer_name |
---|---|---|
Pen | 30 | Sanskriti |
Bag | 1000 | Sanskriti |
Vegetables | 500 | Sanskriti |
Shoes | 5000 | Sanskriti |
Water Bottle | 800 | XYZ |
Mouse | 120 | ABC |
Sun Glasses | 1350 | ABC |
ROLLBACK to sv_update;
SELECT * FROM purchase;
item | price | customer_name |
---|---|---|
Pen | 20 | Sanskriti |
Bag | 1000 | Sanskriti |
Vegetables | 500 | Sanskriti |
Shoes | 5000 | Sanskriti |
Water Bottle | 800 | XYZ |
Mouse | 120 | ABC |
Sun Glasses | 1350 | ABC |
Torch | 850 | ABC |
With this short tutorial we have learnt TCL commands.