What is COMMIT?
COMMIT saves all changes made in a transaction. Makes them permanent.
Simple analogy: Like clicking "Save" button after editing a document.
Basic Syntax
BEGIN;
-- Your changes here
COMMIT;Simple Example
BEGIN;
UPDATE students SET grade = 'A' WHERE student_id = 1;
COMMIT; -- Grade is now saved permanentlyBefore and After COMMIT
Before COMMIT:
- Changes are temporary
- Other users do not see changes
- Can still cancel with ROLLBACK
After COMMIT:
- Changes are permanent
- Everyone sees the changes
- Cannot undo
Real Example
BEGIN;
UPDATE products SET price = 99.99 WHERE product_id = 1;
UPDATE products SET stock = 50 WHERE product_id = 1;
COMMIT; -- Both changes saved permanentlySummary
COMMIT = Save changes permanently
- Like "Save" button
- Makes changes visible to everyone
- Cannot undo after COMMIT