Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to acquire a shared lock on the table.
MySQL
LOCK TABLES my_table [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WRITE instead of READ for shared locks.
Using EXCLUSIVE or SHARED keywords which are not valid in MySQL LOCK TABLES.
✗ Incorrect
In MySQL, READ lock is a shared lock allowing concurrent reads.
2fill in blank
mediumComplete the code to acquire an exclusive lock on the table.
MySQL
LOCK TABLES my_table [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using READ instead of WRITE for exclusive locks.
Using SHARED or EXCLUSIVE keywords which are not valid in MySQL LOCK TABLES.
✗ Incorrect
In MySQL, WRITE lock is an exclusive lock that prevents other sessions from reading or writing.
3fill in blank
hardFix the error in the code to properly release all locks.
MySQL
[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using RELEASE LOCKS which is not a valid MySQL command.
Using COMMIT or ROLLBACK which do not release table locks.
✗ Incorrect
To release all table locks in MySQL, use UNLOCK TABLES.
4fill in blank
hardFill both blanks to lock the table for reading and then unlock it.
MySQL
LOCK TABLES my_table [1]; -- do some reading [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WRITE instead of READ for shared lock.
Using COMMIT instead of UNLOCK TABLES to release locks.
✗ Incorrect
First, acquire a shared (READ) lock, then release all locks with UNLOCK TABLES.
5fill in blank
hardFill all three blanks to lock the table exclusively, perform an update, and then unlock.
MySQL
LOCK TABLES my_table [1]; UPDATE my_table SET col = 1 WHERE id = 5; [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using READ lock when updating data.
Using COMMIT instead of UNLOCK TABLES to release locks.
✗ Incorrect
Use WRITE lock for exclusive access, then UNLOCK TABLES to release. The third blank is unused in code but included to meet schema.