2

我试图让它工作,但得到一个错误t_write was not locked.

我正在从最高值更新 colmake和 colsnsn + 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;
4

1 回答 1

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;
于 2012-08-16T15:07:55.533 回答