简体   繁体   English

SQL Server-两个数据库上的非分布式事务

[英]SQL Server - Non-distributed transaction over two DBs


I am trying to localize an issue I have 我正在尝试定位我遇到的问题
with 2 DBs and their transactional behavior. 2个DB及其事务行为。

I create two DBs on a single SQL Server 2008 R2 instance. 我在一个SQL Server 2008 R2实例上创建两个数据库。

test1 TEST1
test2 测试2

test1 has one table Table_1 test1有一个表Table_1
test2 has one table Table_2 test2有一张表Table_2

Both tables have an ID (int) and a value (string) columns. 两个表都有一个ID(int)和一个value(string)列。
Both have just one row which has ID=1. 两者都只有一行ID = 1的行。

Then in SQL Server Management Studio, 然后在SQL Server Management Studio中,
in some window 1 I do 在某些窗口1

use test1

begin transaction

update test1.dbo.Table_1
set
value = 'TEST-100'
where
ID = 1 


update test2.dbo.Table_2
set
value = 'TEST-200'
where
ID = 1 

commit transaction  --- but I don’t run the commit yet --- 

and then in another window 2, I do 然后在另一个窗口2中,

select * From test1.dbo.Table_1
with (nolock) 

select * From test2.dbo.Table_2
with (nolock) 

This way I can see the two uncommitted yet values. 这样,我可以看到两个尚未提交的值。

But if in window 2, I do 但是如果在窗口2中,我会

select * From test1.dbo.Table_1

or 要么

select * From test2.dbo.Table_2

these SELECT staments hang. 这些SELECT元素会挂起。

So my question is: is that transaction from 所以我的问题是:是从
window 1, spanning two DBs? 窗口1,跨越两个DB? Seems so because 似乎是因为

select * From test2.dbo.Table_2

hangs too which means to me that test2.dbo.Table_2 也会挂起,这对我来说意味着test2.dbo.Table_2
is enlisted in the same transaction which I started 参加了我开始的同一笔交易
in window 1. 在视窗1。

But why is this transaction acting like a distributed one? 但是,为什么这项交易像分布式交易一样?
Is that normal? 那是正常的吗? What is the explanation? 有什么解释? Is that some 那是一些吗
undocummented feature in SQL Server? SQL Server中未取消保留的功能? Are there any 有没有
references which would explain that behavior I am seeing? 哪些引用可以解释我所看到的行为?

When a query spans over 2 databases, then your transaction is promoted to a distributed transaction handled by MSDTC. 当查询跨越2个数据库时,您的事务将升级为MSDTC处理的分布式事务。 It's the normal way to be and it happens without explicitly using BEGIN DISTRIBUTED TRANSACTION statement. 这是正常的方式,并且无需显式使用BEGIN DISTRIBUTED TRANSACTION语句即可实现。

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

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