capypad
0 day streak
sql / intermediate
Snippet

Atomic Transactions with COMMIT

Transactions ensure multiple operations are treated as a single unit. COMMIT saves all pending changes permanently to the database, ensuring data consistency.

snippet.sql
sql
1
2
3
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
Breakdown
1
UPDATE accounts SET balance = ...
The individual data modification steps within the transaction.
2
COMMIT;
The command that finalizes the transaction and makes all changes permanent.