Is there an equivalent for SQL Server#39;s @@error in MySQL(MySQL 中是否有 SQL Server 的 @@error 的等效项)
问题描述
我想对生产数据库运行更新查询,作为优秀的小开发人员,我正在努力使其尽可能安全.我正在做以下事情
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 语句之后提交,如果该语句没有返回错误.如果一个语句返回一个错误,提交或回滚行为取决于错误.见章节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 的 @@error 的等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL 中是否有 SQL Server 的 @@error 的等效项


- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- SQL 临时表问题 2022-01-01