如果查询失败,是否有必要编写ROLLBACK? [英] Is it necessary to write ROLLBACK if queries fail?

查看:197
本文介绍了如果查询失败,是否有必要编写ROLLBACK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写

mysql_query("SET AUTOCOMMIT=0");
mysql_query("START TRANSACTION");

在我写所有查询之前.然后检查它们是否全部都正确,然后输入:

mysql_query("COMMIT");

但是,如果查询之一失败,我将通过COMMIT查询.那么,如果其中一个查询失败,我真的需要ROLLBACK函数吗?因为没有ROLLBACK,它也可以工作.
谢谢.

I write

mysql_query("SET AUTOCOMMIT=0");
mysql_query("START TRANSACTION");

before I write all queries. Then check if all of them are true and then write:

mysql_query("COMMIT");

But if one of query fails, I just pass COMMIT query. So do I really need ROLLBACK function if one of the queries fail? Because without ROLLBACK it also works.
Thanks.

推荐答案

我认为您是在询问是否需要执行ROLLBACK,因为没有它,提交将仍然无法应用.从技术上讲,这是正确的,但这仅是因为自您尚未结束交易以来,交易仍处于打开状态.任何隐式提交事务的事物(例如,开始新事务)都将像您运行了COMMIT一样,这与您想要的相反

I think you're asking if executing ROLLBACK is necessary, since without it the commits still don't get applied. That's technically true, but only because the transaction is still open since you haven't ended it. Anything that implicitly commits the transaction (for example, starting a new transaction) will act as though you ran COMMIT, which is the opposite of what you want

这篇关于如果查询失败,是否有必要编写ROLLBACK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆