작성자 : 장형화 (hhjang97@venus.uos.ac.kr)


###########################
# LOCK TABLES/UNLOCK TABLES 
###########################
문서 
  - MySQL 메뉴얼 "7.23 LOCK TABLES/UNLOCK TABLES syntax" 참고


1. Syntax

LOCK TABLES tbl_name [AS alias] {READ | [LOW_PRIORITY] WRITE}
            [, tbl_name {READ | [LOW_PRIORITY] WRITE} ...]
...
UNLOCK TABLES


2. SQL 예제


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;


** 주의 **

  (UPDATE customer SET value=value+new_value) 
  또는
  LAST_INSERT_ID() 

의 경우 LOCK TABLES 를 사용해야  문제 발생을 줄일수 있다. 


############################
# LAST_INSERT_ID([expr]) 
############################

문서 
  - MySQL 메뉴얼 "See section 20.4.28 mysql_insert_id()" 

mysql> select LAST_INSERT_ID();