sql / beginner
Snippet
Persisting Database Changes via COMMIT
Transactions bundle multiple SQL commands into a single unit of work. The COMMIT statement permanently saves all modifications made within the active transaction to the database.
snippet.sql
sql
1
2
3
BEGIN TRANSACTION;UPDATE accounts SET balance = balance - 100 WHERE id = 1;COMMIT;
Breakdown
1
BEGIN TRANSACTION;
Starts a new database transaction block to group changes together.
2
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
Modifies the balance value for account ID 1 inside the pending transaction.
3
COMMIT;
Saves all changes from the transaction permanently to disk.