2010-08-05 74 views

回答

1

隔離僅適用於適用的表。

請考慮以下情況。在一個會議上,成立了表和視圖:從視圖

create table x (a int, b varchar(10)) 

create table y (c int, d varchar(10)) 

insert into x (a, b) values (1, 'Q') 
insert into x (a, b) values (2, 'W') 
insert into x (a, b) values (3, 'E') 

insert into y (c, d) values (1, 'A') 
insert into y (c, d) values (2, 'S') 
insert into y (c, d) values (3, 'D') 


create view v_test 
as 
select x.a, x.b, y.d 
from x with (readuncommitted) 
    inner join 
    y 
    on x.a = y.c 

選擇從會話1:從v_test

a  b  c 
---- ---- ---- 
1  Q  A 
2  W  S 
3  E  D 

SELECT * 現在打開另一個會話,並啓動一個交易,首先只更新x:

begin transaction 

update x 
set b = 'R' 
where a = 1 

回到會話1,執行視圖。您現在將得到:

a  b  d 
---- ---  --- 
1  R  A 
2  W  S 
3  E  D 

請注意第一行中b的新值。

回到會話2,用仍是交易打開,更新Y:

update y 
set d = 'F' 
where c = 1 

,然後嘗試查詢視圖早在會議1:

select * 
from v_test 

(你會發現它似乎需要相當長的時間。)

查詢仍在執行,回到會話2並提交交易:

(工作階段,現在看起來是這樣的:

begin transaction 

update x 
set b = 'R' 
where a = 1 

update y 
set d = 'F' 
where c = 1 

commit 

回頭看看會話1,結果現在這個出現:

a  b  d 
---  ---  --- 
1  R  F 
2  W  S 
3  E  D 

與d第一的新價值行。

因此,長話多一點,WITH(READUNCOMMITTED)不會傳播。

0

如果您從patrick運行示例,並且在兩個表上都執行readuncommitted,那麼即使事務正在進行,您仍然可以使用它。 你也可以在沒有readuncommitted的情況下運行這個例子,但是將readuncommitted傳遞給視圖中的select,如果傳遞給視圖,它會傳播到視圖中的select。 ex。 select * from v_test with(readuncommitted)