【发布时间】:2019-05-02 20:56:21
【问题描述】:
我相信即使在事务中,插入到具有 default current_timestamp 列的表中的一堆,可能会根据行创建时间具有不同的值,但我不确定 原子 merge 声明是:
Is MERGE an atomic statement in SQL2008?
这是我的测试脚本:
-
代码
if type_id(N'ValuableRow') is not null drop type ValuableRow create type ValuableRow as table ( JustAValue nvarchar(max) ) drop table if exists TestTable create table TestTable( JustAValue nvarchar(max) , Birth datetime2 default current_timestamp ) go --// delete TestTable insert TestTable(JustAValue) values ('1234'), ('5678') declare @rows ValuableRow, @alsoRows ValuableRow insert @rows(JustAValue) values ('abcd'), ('1234'), ('5678'), ('wxyz') merge TestTable y using @rows x on (y.JustAValue=x.JustAValue) when not matched then insert (JustAValue) values (JustAValue) output inserted.JustAValue into @alsoRows ; select * from @alsoRows select * from TestTable
结果显示:
显然,如果操作需要更长的执行时间会发生什么情况是不够的,我想知道merge 是否仍会使所有插入的行具有相同的创建时间?
【问题讨论】:
标签: sql-server merge