下面有一个类似于这些的查询,我需要它在一个更新查询中。由于我是初学者,我使用联接并编写了单行查询,但我得到的错误是
超过锁定等待超时;尝试重新启动事务
下面是每个单独的更新查询..。
update a set id=id-1 where id>'3' and reg='34554';
update b set id=id-1 where id>'3' and reg='34554';
update c set id=id-1 where id>'3' and reg='34554';
update d set id=id-1 where id>'3' and reg='34554';
update e set id=id-1 where id>'3' and reg='34554';下面是我试过的错误,正如上面所说的.
update a
LEFT JOIN b ON b.id=a.id and b.tan=a.tan
LEFT JOIN c ON c.id=b.id and c.tan=b.tan
LEFT JOIN d ON d.id=c.id and d.tan=c.tan
LEFT JOIN e ON e.id=d.id and e.tan=d.tan
SET a.id=b.id=c.id=d.id=e.id=a.id-1
where a.id>'3' and a.tan='34554';发布于 2012-04-05 11:42:19
您可以在存储过程中存储多个sql,然后从java..Id和reg可以通过参数传递。
关于存储过程的信息http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html
你必须在Mysql命令行中这样做..。
Delimiter |
Create procedure (in id_val int, in reg_val int)
Begin
update a set id=id-1 where id>id_val and reg=reg_val;
update b set id=id-1 where id>id_val and reg=reg_val;
update c set id=id-1 where id>id_val and reg=reg_val;
update d set id=id-1 where id>id_val and reg=reg_val;
update e set id=id-1 where id>id_val and reg=reg_val;
End |
delimiter ;我用PHP..。以下链接http://php.net/manual/en/pdo.prepared-statements.php中的信息
爪哇的希望..。此链接可能是有用的http://www.easywayserver.com/jdbc/JDBC-prepared-statement.htm。
发布于 2012-04-05 10:45:31
你必须使用交易
SET autocommit=0;
LOCK TABLES a WRITE, b WRITE, c WRITE, d WRITE, e WRITE
update a set id=id-1 where id>'3' and reg='34554';
update b set id=id-1 where id>'3' and reg='34554';
update c set id=id-1 where id>'3' and reg='34554';
update d set id=id-1 where id>'3' and reg='34554';
update e set id=id-1 where id>'3' and reg='34554';
COMMIT;
UNLOCK TABLES;您可以阅读有关将锁表与事务这里组合的文章。
我不知道,如何用join创建这样的查询。
https://stackoverflow.com/questions/10026939
复制相似问题