SQL Server - transactions roll back on error?(SQL Server - 事务回滚错误?)
问题描述
我们有在 SQL Server 2005 上运行一些 SQL 的客户端应用程序,如下所示:
We have client app that is running some SQL on a SQL Server 2005 such as the following:
BEGIN TRAN;
INSERT INTO myTable (myColumns ...) VALUES (myValues ...);
INSERT INTO myTable (myColumns ...) VALUES (myValues ...);
INSERT INTO myTable (myColumns ...) VALUES (myValues ...);
COMMIT TRAN;
它是由一个长字符串命令发送的.
It is sent by one long string command.
如果其中一个插入失败,或者命令的任何部分失败,SQL Server 会回滚事务吗?如果它不回滚,我是否必须发送第二个命令来回滚它?
If one of the inserts fail, or any part of the command fails, does SQL Server roll back the transaction? If it does not rollback, do I have to send a second command to roll it back?
我可以提供有关我正在使用的 api 和语言的详细信息,但我认为 SQL Server 应该对任何语言做出相同的响应.
I can give specifics about the api and language I'm using, but I would think SQL Server should respond the same for any language.
推荐答案
您可以在事务之前设置 set xact_abort on 以确保 sql 在发生错误时自动回滚.
You can put set xact_abort on before your transaction to make sure sql rolls back automatically in case of error.
这篇关于SQL Server - 事务回滚错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server - 事务回滚错误?
基础教程推荐
- 无法解决整理冲突 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
