SQL Transaction Control Language (TCL) – COMMIT and ROLLBACK
Transaction Control Language (TCL) in SQL is used to manage transactions in a database. A transaction is a sequence of operations performed as a single logical unit of work. TCL commands ensure data integrity and consistency.
1. COMMIT
Definition: Saves all the changes made by the current transaction permanently to the database.
Syntax:
COMMIT;
Example:
INSERT INTO Student (student_id, name, dept_id) VALUES (101, 'John Doe', 1); COMMIT;
The new student record is now permanently saved in the Student table.
2. ROLLBACK
Definition: Undoes all changes made by the current transaction, reverting the database to its previous state.
Syntax:
ROLLBACK;
Example:
UPDATE Student SET dept_id = 2 WHERE student_id = 101; ROLLBACK;
The update is undone and the student’s department remains unchanged.
Lab Practice Tasks
- Insert a few rows into the Student table and COMMIT them.
- Update a record and then use ROLLBACK to undo changes.
- Perform multiple operations in a transaction and test COMMIT vs ROLLBACK.
✔ Blogger-ready HTML | Inline CSS | SQL TCL Tutorial
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন