What is a transaction in SQL?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex MySQL / SQL topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
A transaction is a sequence of one or more SQL operations treated as a single logical unit of work. Either ALL operations succeed (COMMIT) or ALL are undone (ROLLBACK), ensuring the database remains in a consistent state. Classic example: bank transfer — debit one account and credit another. If the credit fails after the debit, the debit must be rolled back. Transaction control: START TRANSACTION; (or BEGIN;) — begins the transaction; COMMIT; — saves all changes permanently; ROLLBACK; — reverts all changes made since the transaction started; SAVEPOINT name; — creates a checkpoint within a transaction; ROLLBACK TO SAVEPOINT name; — rolls back to the savepoint without undoing the entire transaction. Auto-commit: MySQL auto-commits each statement by default (each statement is its own transaction). Disable with SET autocommit = 0; or use explicit START TRANSACTION. Transactions are only supported by transactional storage engines — InnoDB supports transactions; MyISAM does not. In application code, always wrap multi-step operations that must be atomic in a transaction.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last MySQL / SQL project, I used this when...' immediately makes your answer more credible and memorable.