Junior — Middle
Explain what a transactional control language (TCL) is in database systems.
sobes.tech AI
Answer from AI
Transactional Control Language (TCL) is a subset of SQL designed for managing transactions in a database. Transactions ensure data integrity by allowing a group of operations to be executed as a single unit.
Main TCL commands:
- BEGIN TRANSACTION (or simply START TRANSACTION) — start of a transaction.
- COMMIT — confirm all changes made within the transaction.
- ROLLBACK — cancel all changes made since the start of the transaction.
Example in SQL:
BEGIN TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
-- If all operations are successful
COMMIT;
-- If an error occurs
ROLLBACK;
Thus, TCL helps ensure that data operations are either fully completed or not executed at all, preventing partial changes and errors.