LOCK and UNLOCK TABLES
LOCK and UNLOCK TABLES:
Using LOCK TABLE query we can lock base tables for the current thread. If any of the tables are locked by other threads, it blocks until all locks can be acquired. UNLOCK TABLES releases any locks held by the current thread. All tables that are locked by the current thread are implicitly unlocked when the thread issues another LOCK TABLES, or when the connection to the server is closed.
Syntax:
LOCK TABLE [table name] [type of lock];
UNLOCK TABLE ;
Example:
1) LOCK TABLE salary READ;
SELECT count(*) FROM salary AS sal;
2) UNLOCK TABLE;
SELECT (*) FROM salary AS sal;
Output:
1) Table ’sal’ was not locked with LOCK TABLES
2)750.
