6.5 Locks and Concurrency
Transaction control is relatively easy when you’re the only one working on the database. You can freely read or write rows without worrying about anyone else. However, things take a different turn when you have multiple users working on the same database.
What if two people attempt to update the same row(s) at the exact same time? How would the database engine handle those records—toss a coin and apply the lucky one?
What if user A reads data from multiple related tables while user B runs a deletion of them? It’s possible for A to find a row but not find the corresponding foreign key row because the entries were being deleted at that time.
Luckily, SQL empowers us with mechanisms for dealing with such risks. In this ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access