InterviewBuddy
All interview questions

What is the purpose of a database transaction?

Beginner

Answer

A transaction groups related database operations so they can commit together or roll back together. It helps maintain invariants when one logical action spans multiple writes.

Explanation

Transactions do not automatically solve every concurrency problem. Choose isolation and constraints appropriate to the invariant.

Example

BEGIN; UPDATE accounts ...; INSERT INTO transfers ...; COMMIT;