What is a SAVEPOINT in SQL?
Short answer: A SAVEPOINT is a way to set a point within a transaction to which you can later roll back if necessary. It provides more granular control, allowing partial rollback rather than undoing the entire transaction. When to use: When you want to mark certain stages within a transaction and allow for partial rollback if an error occurs.
Example code
BEGIN TRANSACTION; SAVEPOINT sp1; UPDATE employees SET salary = 5000 WHERE id = 1; - Something goes wrong ROLLBACK TO sp1; -- Rolls back to the savepoint, undoing only the changes after it COMMIT;
Real-world example (ShopNest)
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png