手册上说:“
当您使用LOCK TABLES时,您必须锁定您打算在查询中使用的所有的表。虽然使用LOCK TABLES语句获得的锁定仍然有效,但是您不能访问没有被此语句锁定的任何的表。同时,您不能在一次查询中多次使用一个已锁定的表——使用别名代替,在此情况下,您必须分别获得对每个别名的锁定。
”。不能在一次查询中多次使用一个已锁定的表,那么,如果我在执行的中间时候需要insert两次怎么办?select * from tb1 where id=11;
insert into tb2 set aa=bb;
insert into tb2 set aa=cc;
update tb3 set xxx=555;这样,怎么办?insert 语句不能使用别名吧?

解决方案 »

  1.   

    没有任何问题啊。
    你想问的是什么?
    mysql> create table t_haosee (aa int);
    Query OK, 0 rows affected (0.05 sec)mysql> LOCK TABLES t_haosee WRITE;
    Query OK, 0 rows affected (0.00 sec)mysql> insert into t_haosee set aa=1;
    Query OK, 1 row affected (0.03 sec)mysql> insert into t_haosee set aa=2;
    Query OK, 1 row affected (0.02 sec)mysql> unlock tables;
    Query OK, 0 rows affected (0.00 sec)mysql> select * from t_haosee;
    +------+
    | aa   |
    +------+
    |    1 |
    |    2 |
    +------+
    2 rows in set (0.00 sec)mysql>
      

  2.   

    这个在手册中有例子说明的。下面这是一个查询。mysql> LOCK TABLES t_haosee WRITE;
    Query OK, 0 rows affected (0.00 sec)mysql> insert into t_haosee select * from t_haosee;
    ERROR 1100 (HY000): Table 't_haosee' was not locked with LOCK TABLES
    mysql>
      

  3.   

    NND,一直理解的是同一个处理流程里不能使用两次-_-!!!!!