Loading Depth Study
Preparing your workspace
A transaction groups related database operations so they can be handled as one logical unit with defined consistency behavior.
Some actions require multiple database changes to succeed together. For example, creating an order and reducing inventory may need to happen consistently. A transaction can commit all required changes or roll them back when something fails. ACID describes important transaction properties: Atomicity, Consistency, Isolation, and Durability. Exact behavior varies by database system and configuration, but the core goal is reliable state changes.
A payment-related workflow might need to create an order and record its payment status without leaving the database in a half-updated state.
BEGIN; INSERT INTO orders (...) VALUES (...); UPDATE inventory SET quantity = quantity - 1 WHERE product_id = 10; COMMIT;
The related operations are committed as one transaction when they complete successfully.