How do you set autocommit in an SQL Server session?(如何在 SQL Server 会话中设置自动提交?)
问题描述
如何在 SQL Server 会话中设置自动提交?
How do you set autocommit in an SQL Server session?
推荐答案
你可以通过设置implicit_transactions OFF来开启自动提交:
You can turn autocommit ON by setting implicit_transactions OFF:
SET IMPLICIT_TRANSACTIONS OFF
当设置为 ON 时,它返回到隐式事务模式.在隐式事务模式下,您所做的每一次更改都会启动一个您必须手动提交的事务.
When the setting is ON, it returns to implicit transaction mode. In implicit transaction mode, every change you make starts a transactions which you have to commit manually.
也许举个例子更清楚.这会将更改写入数据库:
Maybe an example is clearer. This will write a change to the database:
SET IMPLICIT_TRANSACTIONS ON
UPDATE MyTable SET MyField = 1 WHERE MyId = 1
COMMIT TRANSACTION
这不会将更改写入数据库:
This will not write a change to the database:
SET IMPLICIT_TRANSACTIONS ON
UPDATE MyTable SET MyField = 1 WHERE MyId = 1
ROLLBACK TRANSACTION
以下示例将更新一行,然后抱怨没有要提交的事务:
The following example will update a row, and then complain that there's no transaction to commit:
SET IMPLICIT_TRANSACTIONS OFF
UPDATE MyTable SET MyField = 1 WHERE MyId = 1
ROLLBACK TRANSACTION
就像 Mitch Wheat 所说的,自动提交是 Sql Server 2000 及更高版本的默认设置.
Like Mitch Wheat said, autocommit is the default for Sql Server 2000 and up.
这篇关于如何在 SQL Server 会话中设置自动提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 SQL Server 会话中设置自动提交?
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 无法解决整理冲突 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
