Skip to content

LOCK

START TRANSACTION;
SELECT * FROM Employees WHERE EmployeeID = 1 FOR UPDATE;
+------------+----------+----------+
| EmployeeID | Name | Position |
+------------+----------+----------+
| 1 | John Doe | Manager |
+------------+----------+----------+

The above SQL commands begin a transaction, then select a record from the ‘Employees’ table with ‘EmployeeID’ of 1 and lock it for update. This prevents other transactions from modifying or deleting the selected row until the current transaction completes.