What are database transactions

· Category: SQL & Databases

Short answer

A transaction is a sequence of operations treated as a single unit of work. It must be Atomic, Consistent, Isolated, and Durable (ACID). For schema design context, see how to design a database schema from scratch. For migration safety, see how to implement database migrations.

Steps

  1. Start a transaction: BEGIN;
  2. Execute one or more SQL statements
  3. Commit if all succeed: COMMIT;
  4. Rollback on error: ROLLBACK;
  5. Choose the appropriate isolation level for your use case

Tips