手册上说:“
当您使用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 语句不能使用别名吧?
当您使用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 语句不能使用别名吧?
你想问的是什么?
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>
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>