Published by : Obay Salah , November 19, 2024

 The database administrator can manually lock the table using the Lock Table command.

LOCK TABLE TEST IN SHARE MODE;


Thus, we have applied a Shared Lock on the TEST table manually.

Now, if we were to apply an Exclusive Lock on the same table from another session, the operation would fail as long as the Shared Lock on the table remains in place.

LOCK TABLE TEST IN EXCLUSIVE MODE NOWAIT;


Notice that I used the NOWAIT option while performing the lock; otherwise, the session would have been blocked.

Now, from the first session, we can release the Shared Lock using the COMMIT command.

Then, we can reapply the Exclusive Lock on the table from the second session.

Tags : Database

You May Also Like

Comments

no comment yet!