In transactions, you can use the lock table command to:
To immediately lock the entire table, rather than waiting for lock promotion to take effect.
When the query or transactions uses multiple scans, and none of the scans locks a sufficient number of pages or rows to trigger lock promotion, but the total number of locks is very large.
When large tables, especially those using datarows locking, need to be accessed at transaction level 2 or 3, and lock promotion is likely to be blocked by other tasks. Using lock table can prevent running out of locks.
The table locks are released at the end of the transaction.
lock table allows you to specify a wait period. If the table lock cannot be granted within the wait period, an error message is printed, but the transaction is not rolled back.