Databases · Senior · Question 9 of 75

What is write skew?

-- Rule: at least one doctor must be on call.
-- T1 and T2 both see 2 doctors on call, each takes one off.
UPDATE doctors SET on_call = false WHERE id = 1; -- T1
UPDATE doctors SET on_call = false WHERE id = 2; -- T2

Explanation

Repeatable Read (snapshot isolation) allows it. Serializable isolation, explicit locks (FOR UPDATE on the rows checked) or a constraint prevent it.

Further reading

Problem with a question

Databases · Senior · question 9

Test yourself

Take the Databases · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz