Examples for business, study, careers, love, and more...
Examples :: MYSQL Examples :: Example of Lock Tables and Unlock Tables Mysql Statement

Example of Lock Tables and Unlock Tables Mysql Statement:

LOCK TABLES t1 READ;
SELECT COUNT(*) FROM t1;

LOCK TABLE t READ;
SELECT * FROM t AS myalias;
LOCK TABLES trans READ, customer WRITE;
SELECT SUM(value) FROM trans WHERE customer_id=some_id;
UPDATE customer
SET total_value=sum_from_previous_statement
WHERE customer_id=some_id;
UNLOCK TABLES;

Example of Mysql Lock Tables and Unlock Tables

LOCK TABLES
tbl_name [[AS] alias] lock_type
[, tbl_name [[AS] alias] lock_type] ...
lock_type:
READ [LOCAL]
| [LOW_PRIORITY] WRITE

UNLOCK TABLES