Page 1 of 1

Locking a Table during a Query

Posted: Mon Nov 24, 2003 3:20 pm
by Gen-ik
I've checked the manual as usual but can't find anything that relates to this.. but knowing me I've probably just over-looked it.

How would I go about locking a MySQL table during a query? I know it can be done but I can't remember how.


Thanks.

Posted: Mon Nov 24, 2003 3:26 pm
by microthick
http://www.mysql.com/doc/en/LOCK_TABLES.html

From the above page:

mysql> LOCK TABLES trans READ, customer WRITE;
mysql> SELECT SUM(value) FROM trans WHERE customer_id=some_id;
mysql> UPDATE customer SET total_value=sum_from_previous_statement
-> WHERE customer_id=some_id;
mysql> UNLOCK TABLES;

Posted: Mon Nov 24, 2003 4:01 pm
by Gen-ik
Cheers mate v.helpful.