简体   繁体   English

如果运行期间发生错误,是否将提交SQL Server事务?

[英]Will a SQL Server transaction commit if an error happens during the run?

I have a transaction that does many OPENQUERY to many different server. 我有一个对许多不同的服务器执行许多OPENQUERY的事务。 one of those server is MySQL. 这些服务器之一是MySQL。

If I start transaction, and then insert/update data into multiple linked servers. 如果我开始事务,然后将数据插入/更新到多个链接的服务器中。 If an error happened during this transaction (for example linked server is not available) will SQL Server automatically rollback the entire transaction and tells the linked servers to rollback? 如果在此事务期间发生错误(例如,链接服务器不可用),SQL Server是否会自动回滚整个事务并告诉链接服务器回滚? Or will it commit the transaction anyway, and there is a chance that a data in committed to one server but not others? 还是无论如何都会提交事务,并且数据有可能提交给一台服务器而不是其他服务器?

BEGIN TRAN T1;
 INSERT INTO OPENQUERY...
 INSERT INTO OPENQUERY....
 INSERT INTO table1.....
 UPDATE table 2 .....
 COMMIT TRAN T1;

Since you don't havea try catch block, yes there is a strong possiblity that the data won't rollback. 由于您没有尝试catch块,因此,很可能不会回滚数据。 YOu need to specify what to do in teh case of an error. 您需要指定发生错误时的处理方法。 You should never wrte a transaction without a try catch block and a rollback strategy. 没有try catch块和回滚策略,切勿编写事务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM