0
0
MySQLquery~5 mins

Lock types (shared, exclusive) in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a shared lock in a database?
A shared lock allows multiple transactions to read a resource at the same time but prevents any transaction from modifying it until all shared locks are released.
Click to reveal answer
beginner
What is an exclusive lock in a database?
An exclusive lock allows only one transaction to write or modify a resource, blocking other transactions from reading or writing it until the lock is released.
Click to reveal answer
beginner
Why do databases use shared and exclusive locks?
Databases use shared and exclusive locks to keep data consistent and avoid conflicts when multiple users access or change the same data at the same time.
Click to reveal answer
beginner
Can multiple transactions hold an exclusive lock on the same resource simultaneously?
No, only one transaction can hold an exclusive lock on a resource at a time to prevent conflicts during data modification.
Click to reveal answer
intermediate
What happens if a transaction tries to acquire an exclusive lock while shared locks are held on the same resource?
The transaction must wait until all shared locks are released before it can get the exclusive lock, ensuring no other transaction is reading the resource during modification.
Click to reveal answer
Which lock type allows multiple transactions to read a resource simultaneously?
AExclusive lock
BShared lock
CUpdate lock
DNo lock
What does an exclusive lock prevent?
AOther transactions from reading or writing the locked resource
BOnly other transactions from reading the resource
COnly other transactions from writing the resource
DNothing, it allows all access
If a resource has shared locks, what must happen before an exclusive lock can be granted?
AOne shared lock must be converted to exclusive
BExclusive lock can be granted immediately
CAll shared locks must be released
DShared locks are ignored
Which lock type is typically used when a transaction only needs to read data?
AShared lock
BExclusive lock
CDeadlock
DNo lock
What is the main goal of using locks in a database?
ATo delete old data automatically
BTo speed up queries
CTo allow unlimited simultaneous writes
DTo keep data consistent and avoid conflicts
Explain the difference between shared and exclusive locks in a database.
Think about who can read or write when each lock is held.
You got /4 concepts.
    Describe why databases need to use lock types like shared and exclusive locks.
    Consider what happens if many users change data at the same time without locks.
    You got /4 concepts.