Shared and exclusive locks
- SQL course
- Advanced
- Lesson 61/81
- 4 min
Learn shared vs exclusive locks.
Shared and Exclusive
A shared lock allows reads, an exclusive lock only one operation.
-- Shared: SELECT (okuma kilidi)
-- Exclusive: UPDATE/DELETE (yazma kilidi)Shared reads, exclusive writes.
Shared and Exclusive — details
Multiple shared locks can coexist. An exclusive lock is alone.
Readers don't block each other, but while one transaction writes (exclusive), others wait to read or change that row.
Practice Shared and Exclusive
Exclusively lock a row with SELECT ... FOR UPDATE.
Starter code
-- exclusive lock
SELECT * FROM accounts WHERE id = 1Sample solution
SELECT * FROM accounts WHERE id = 1 FOR UPDATE;Expected output
id balance 1 500
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Exclusive
____ → yazma kilidi
Exclusive → yazma kilidi
Explanation: Exclusive is the right answer.
2 How many operations does an exclusive lock allow?
- Two
- Unlimited
- Three
- One Correct answer
Explanation: An exclusive lock allows only one operation.
3 Shared and exclusive locks: match the terms
| Term | Meaning |
|---|---|
shared |
read |
exclusive |
write |
many shared |
compatible |
one exclusive |
exclusive |