繁体   English   中英

Upsert选项:rowversion与datetime

[英]Upsert options: rowversion vs datetime

很多时候,我需要将一个大表的数据(称为源)移动到它的克隆(称为目标)。 由于尺寸很大,我宁愿向上插入,而不仅仅是删除/插入全部。

为了简便起见,我们假设一个名为“ id”的int PK col。

到目前为止,为了做到这一点,我使用了两个表中都存在的datetime字段dbupddate,该字段保存了最近一次插入/更新行的时间。 这是通过使用触发器完成的,该触发器对于任何插入/更新都将dbupddate设置为getdate()。

因此,到目前为止,我的常规代码看起来像这样:

update t set (col1=s.col1,col2=s.col2 etc)
from source s
inner join target t on s.id=t.id and s.dbupddate>t.dbupddate

insert target 
select * from source s
where not exists (select 1 from target t where t.id=s.id)

最近我偶然发现了rowversion 我已在某种程度上阅读并理解了它的功能,但是实际上我想知道在将dbupddate更改为rowversion而不是datetime时有什么好处/缺点。

尽管datetime包含在某些情况下可能有用的信息,但由于系统datetime始终有被更改和失去准确性的风险,因此rowversion更为可靠。 就您而言,我个人更喜欢rowversion的可靠性。

暂无
暂无

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

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