TCL stands for Transaction Control Language, and it is a subset of SQL commands that allows you to manage the transactions in a database. Transactions are a sequence of operations that are performed as a single logical unit of work. Transactions ensure data integrity and consistency by following the ACID properties: Atomicity, Consistency, Isolation, and Durability. Some of the most common TCL commands are:
COMMIT: This command is used to save the changes made by a transaction permanently to the database. Once a transaction is committed, it cannot be rolled back. The syntax of the COMMIT command is:
COMMIT
ROLLBACK: This command is used to undo the changes made by a transaction and restore the database to its previous state. A transaction can be rolled back before it is committed. The syntax of the ROLLBACK command is:
ROLLBACK;
SAVEPOINT: This command is used to create a point within a transaction to which you can later roll back. A savepoint can be useful when you want to partially undo a transaction. The syntax of the SAVEPOINT command is:
SAVEPOINT savepoint_name;
To roll back to a savepoint, you can use the following syntax:
ROLLBACK TO savepoint_name;