在MySQL中是否有SQL Server的@@错误 [英] Is there an equivalent for SQL Server's @@error in MySQL

查看:302
本文介绍了在MySQL中是否有SQL Server的@@错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对一个生产数据库和一个好的小开发者运行一个更新查询,我试图使其尽可能安全。我正在寻找做以下

I want to run an update query against a production database and as good little developer I am trying to make it as safe as possible. I am looking to do the following

BEGIN TRANSACTION
    UPDATE table_x SET col_y = 'some_value'
    .
    .
    .
IF (@@error <> 0)
BEGIN
    ROLLBACK
END
ELSE
BEGIN
    COMMIT
END

以上应该在SQL Server中工作,但我需要这个工作对MySQL数据库。

The above should work in SQL Server but I need this to work against a MySQL database.

编辑:
对不起,有超过1个语句要执行。是的,我知道不需要在一个事务中包装单个查询。

Sorry, there is more than 1 statement to execute. Yes I am aware of not needing to wrap a single query in a transaction.

推荐答案

我不认为这是必要的有隐式提交/回滚的概念。

I don't think this is necessary as there is the concept of implicit commit/rollback.

MySQL文档


默认情况下,MySQL启动会话

自动提交模式启用的每个新连接,因此MySQL在每个SQL语句之后提交
a,如果
该语句没有返回
错误。如果语句返回
错误,则提交或回滚行为
取决于错误。请参见
13.6.13节InnoDB错误处理。

By default, MySQL starts the session for each new connection with autocommit mode enabled, so MySQL does a commit after each SQL statement if that statement did not return an error. If a statement returns an error, the commit or rollback behavior depends on the error. See Section 13.6.13, "InnoDB Error Handling".

这篇关于在MySQL中是否有SQL Server的@@错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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