我正试图让这个工作,但得到错误t_write was not locked.
我正在更新col make
和col sn
的最高值sn + 1
LOCK TABLES 1_makes AS t_read READ, 1_makes as t_write WRITE;
UPDATE t_write
SET
make = 'Pioneer',
sn = (SELECT
*
from
(SELECT
MAX(sn)
FROM
t_read
WHERE
id <> 0) as new_sn) + 1
WHERE
id = 2;
UNLOCK TABLES;
答案 0 :(得分:3)
这个怎么样:
LOCK TABLES 1_makes WRITE, 1_makes AS t_read READ;
UPDATE 1_makes
SET
make = 'Pioneer',
sn = (SELECT
*
from
(SELECT
MAX(sn)
FROM
1_makes AS t_read
WHERE
id <> 0) as new_sn) + 1
WHERE
id = 2;
UNLOCK TABLES;