What does the ROLLBACK command do?
The ROLLBACK command undoes every change made within the current transaction and returns the database to the state it was in before the transaction started.
It's used when an error occurs or when changes need to be cancelled before committing (COMMIT).
Example
sql
START TRANSACTION;
UPDATE users SET balance = balance - 100 WHERE id = 1;
UPDATE users SET balance = balance + 100 WHERE id = 2;
ROLLBACK;After ROLLBACK, both changes are undone - the database looks as though the transaction never ran at all.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.