如何在 SQL Server 会话中设置自动提交?
如何在 SQL Server 会话中设置自动提交?
How do you set autocommit in an SQL Server session?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何在 SQL Server 会话中设置自动提交?
How do you set autocommit in an SQL Server session?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
您可以通过将implicit_transactions设置为OFF来打开自动提交:
当设置为ON时,它将返回到隐式事务模式。 在隐式事务模式下,您所做的每个更改都会启动一个必须手动提交的事务。
也许举个例子就更清楚了。 这会将更改写入数据库:
这不会将更改写入数据库:
下面的示例将更新一行,然后抱怨没有要提交的事务:
就像 Mitch Wheat 所说,自动提交是 Sql Server 2000 的默认设置及以上。
You can turn autocommit ON by setting implicit_transactions OFF:
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:
This will not write a change to the database:
The following example will update a row, and then complain that there's no transaction to commit:
Like Mitch Wheat said, autocommit is the default for Sql Server 2000 and up.
我想要一种更持久、更快捷的方法。 因为我往往会忘记在编写实际的更新/插入查询之前添加额外的行。
我通过选中“选项”中的SET IMPLICIT_TRANSACTIONS复选框来完成此操作。
导航到“选项” 在 Microsoft SQL Server Management Studio 中选择工具>选项>查询执行>SQL Server>ANSI。
只需确保在执行完查询后执行
commit
或rollback
即可。 否则,您运行查询的表将被其他表锁定。I wanted a more permanent and quicker way. Because I tend to forget to add extra lines before writing my actual Update/Insert queries.
I did it by checking SET IMPLICIT_TRANSACTIONS check-box from Options.
To navigate to Options Select Tools>Options>Query Execution>SQL Server>ANSI in your Microsoft SQL Server Management Studio.
Just make sure to execute
commit
orrollback
after you are done executing your queries. Otherwise, the table you would have run the query will be locked for others.自动提交是SQL Server默认的事务管理模式。 (SQL 2000 及以上)
参考:自动提交事务
Autocommit is SQL Server's default transaction management mode. (SQL 2000 onwards)
Ref: Autocommit Transactions
使用 SQLServer 2005 Express,我发现即使关闭了自动提交,也可以提交对数据库表的插入,而无需我从 Management Studio 会话中实际发出提交命令。 唯一的区别是,当自动提交关闭时,我可以回滚所有插入; *打开自动提交,我不能。*
实际上,我错了。关闭自动提交模式后,我只能在发出命令的 QA(查询分析器)窗口中看到更改。 如果我弹出一个新的 QA(查询分析器)窗口,我看不到第一个窗口(会话)所做的更改,即它们没有提交! 我必须发出明确的提交或回滚命令才能使更改对其他会话(QA 窗口)可见 - 我的错! 一切正常。
With SQLServer 2005 Express, what I found was that even with autocommit off, insertions into a Db table were committed without my actually issuing a commit command from the Management Studio session. The only difference was, when autocommit was off, I could roll back all the insertions; with *autocommit on, I could not.*
Actually, I was wrong. With autocommit mode off, I see the changes only in the QA (Query Analyzer) window from which the commands were issued. If I popped a new QA (Query Analyzer) window, I do not see the changes made by the first window (session), i.e. they are NOT committed! I had to issue explicit commit or rollback commands to make changes visible to other sessions(QA windows) -- my bad! Things are working correctly.