Two transactions both see one seat remaining and both sell it. How can the database prevent overselling?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
Make the availability check and decrement part of an atomic conditional update, such as updating only when remaining is greater than zero, and confirm that exactly one row was affected. Create the reservation in the same transaction and roll back if another required step fails. Row locking or an appropriate serializable transaction can also work, with deadlock or serialization-failure retry handling. A prior SELECT followed by an unprotected UPDATE is vulnerable to races. Define cancellation and expiration behavior so inventory is restored consistently.
Related Questions in SQL & Relational Databases
What are Clustered and Non-Clustered Indexes in SQL, and when should you use each?
Intermediate level • 443 views
Explain Redis In-Memory Data Structures and Common Caching Patterns (Cache-Aside, Write-Through, Write-Behind).
Intermediate level • 63 views
How do INNER JOIN and LEFT JOIN differ when a customer has no orders?
Easy level • 59 views
A LEFT JOIN report counts one order for customers who have none. What caused it?
Medium level • 58 views
Explain SQL ACID properties and the differences between READ COMMITTED and REPEATABLE READ isolation levels.
Intermediate level • 55 views