SQL Server Interview Question #144
What is ROLLBACK?
Transactions, Locking, Blocking & Deadlocks Senior Advanced
Detailed Explanation
ROLLBACK reverses changes made by an active transaction back to its beginning or to a specified savepoint, depending on the syntax and transaction state.
It is commonly used in error handling so a partially completed business operation does not leave inconsistent data.
Code Example
BEGIN TRANSACTION;
DELETE FROM dbo.OrderItems
WHERE OrderId = 100;
-- A validation fails:
ROLLBACK TRANSACTION;