bg_image
header

Transaction Control Language - TCL

Transaction Control Language (TCL) is a subset of SQL used to manage transactions in a database. A transaction is a logical unit of work that may consist of one or more SQL statements—typically INSERT, UPDATE, or DELETE—that should be executed together.

TCL provides commands to ensure that transactions are properly completed or rolled back in case of errors.

Main TCL Commands:

Command Description
COMMIT Saves all changes made in the current transaction permanently to the database.
ROLLBACK Undoes all changes made since the last COMMIT.
SAVEPOINT Creates a named point within a transaction that you can roll back to later.
ROLLBACK TO SAVEPOINT Reverts changes back to a specific savepoint.
SET TRANSACTION Defines characteristics for the current transaction (e.g., isolation level).
BEGIN;

UPDATE account SET balance = balance - 100 WHERE account_id = 1;
UPDATE account SET balance = balance + 100 WHERE account_id = 2;

COMMIT;

→ Both updates are completed together. If an error occurs, you could use ROLLBACK to cancel both operations.

Note:

TCL commands only work in database systems that support transactions (e.g., PostgreSQL, Oracle, or MySQL with InnoDB).


Created 1 Day 19 Hours ago
Commit Database Databases MySQL Oracle DB PostgreSQL Postgres SQL SQLite Strategies Structured Query Language - SQL Transaction Control Language - TCL

Leave a Comment Cancel Reply
* Required Field
Random Tech

Amazon Web Services - AWS


1200px-Amazon_Web_Services_Logo.svg.png