🗄️ Database Design / Normalization
Beginner
What is a transaction in a database?
Answer
A transaction is a unit of work that groups one or more SQL statements into a single atomic operation. All statements either succeed together (COMMIT) or are all undone (ROLLBACK). Transactions ensure the ACID properties: Atomicity, Consistency, Isolation, and Durability. Example: a bank transfer — debit one account and credit another — must be atomic; you cannot have the debit succeed without the credit. Syntax: BEGIN TRANSACTION; UPDATE accounts SET balance = balance - 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE id = 2; COMMIT;
Previous
What are the differences between TRUNCATE, DELETE, and DROP?
Next
What does ACID stand for in databases?