如何在SQL Server会话中设置自动提交? [英] How do you set autocommit in an SQL Server session?

查看:448
本文介绍了如何在SQL Server会话中设置自动提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在SQL Server会话中设置自动提交?

How do you set autocommit in an SQL Server session?

推荐答案

您可以通过将hidden_​​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会话中设置自动提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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