有没有办法防止非持久计算列在事务中更新?
我拼凑了一个示例,该示例表明这些列在使用非确定性函数时可以更新(在本例中getutcdate()
)。这不是破坏了交易的一致性要求吗?我曾尝试使用事务级别来防止这种情况(可序列化和快照),但没有帮助。
询问:
set nocount on;
create table dbo.TransactionTest (
[Timestamp] datetime,
IsUpdated as case when datediff(second, [Timestamp], getutcdate()) >= 1 then 1 else 0 end
);
insert into dbo.TransactionTest ([Timestamp]) values (getutcdate());
begin tran
select *
from dbo.TransactionTest;
waitfor delay '00:00:01';
select *
from dbo.TransactionTest;
rollback
drop table dbo.TransactionTest;
结果:
Timestamp IsUpdated
----------------------- -----------
2017-03-19 00:44:28.130 0
Timestamp IsUpdated
----------------------- -----------
2017-03-19 00:44:28.130 1