我有7个SQL查询来执行以下任务:

1. UPDATE Customer SET CustomerService = 'perta' WHERE FirstName = 'john';
2. UPDATE Customer SET Flag = 1 WHERE OrderNum BETWEEN 2 AND 29;
3. UPDATE Customer SET PurchaseNum = PurchaseNum + 60 WHERE OrderNum BETWEEN 2 AND 29;
4. UPDATE Customer SET OrderNum = OrderNum + 60 WHERE OrderNum BETWEEN 2 AND 29;
5. UPDATE Customer SET PurchaseNum = PurchaseNum - 28 WHERE (PurchaseNum > 29 AND PurchaseNum <= 89) AND (Flag <> 1);
6. UPDATE Customer SET OrderNum = OrderNum - 28 WHERE (OrderNum > 29 AND OrderNum <= 89) AND (Flag <> 1);
7. UPDATE Customer SET Flag = 0 WHERE OrderNum BETWEEN 62 AND 89;

是否可以将这些sql查询“压缩”为1个查询?
因为我担心用户通过按esc按钮(在他/她按下submit按钮之后)来取消进程,所以这些序列将在中间中断,我的表也会很混乱。

最佳答案

如果您使用的是mysql,那么可以看到这个链接,它向您展示了如何在mysql中实现事务。
http://dev.mysql.com/doc/refman/5.5/en/commit.html
事务在许多情况下都有助于我们,并且您在需要更新多个数据库表的情况下处理其中一个。

关于mysql - 将7个这样的SQL查询转换为单个查询,是否可能?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10103431/

10-10 02:54