Atomicity makes every statement in a transaction commit or roll back as one logical unit. The statements either all succeed or all fail, protecting multi-step updates from partial completion. section 7.1 section 1.2.1
Mistake: assuming BEGIN TRANSACTION guarantees automatic cleanup after an error.
- A stored procedure can leave a transaction open when an operation fails. Check SELECT @@TRANCOUNT; an unexpected value of 1 means the transaction still needs an explicit ROLLBACK. section 7.1
- Use structured error handling, including TRY...CATCH and an explicit rollback path, so failures do not leave the transaction active. section 7.1
Sales-order insertion
InsertSalesOrder begins a transaction before inserting sales-order data. A valid execution completes the order; an invalid product ID raises a foreign-key error, showing why the procedure needs a rollback-aware error path.












