[英]SQL Server rowversion without adding a column
Typically to expose version data you'd have to add a column of type rowversion
, but this operation would take quite a while on a large table.通常要公开版本数据,您必须添加一个rowversion
类型的rowversion
,但此操作在大表上需要很rowversion
。 I did it anyway in a dev sandbox environment, and indeed it took a while, but I also noticed that the column was populated with some meaningful-looking initial value.无论如何,我是在开发沙盒环境中完成的,确实花了一段时间,但我也注意到该列填充了一些看起来有意义的初始值。 I expected it to be all 0's or 1's to indicate that each row is in some sort of "initial" state (after all, there was no history before this), but what I saw were what looked like accurate values for each row (they were all different, non-default-looking values).我希望它全是 0 或 1 来表示每一行都处于某种“初始”状态(毕竟,在此之前没有历史记录),但我看到的是每一行的准确值(它们都是不同的、非默认值)。
Where did they come from?哪儿来的? It seems like the rowversion
is being tracked behind the scenes anyway, regardless of whether you've exposed it in a column.无论如何,无论您是否在列中公开它,似乎rowversion
都在幕后进行跟踪。 If so, can I get at it directly without adding the column?如果是这样,我可以在不添加列的情况下直接获取它吗? Like maybe some kind of system function I can call directly?就像我可以直接调用的某种系统函数一样? I really want to avoid downtime, and I also have a huge number of existing queries so migration to a different table/view/combo is not an option (as suggested in other related questions).我真的很想避免停机,而且我还有大量现有查询,因此迁移到不同的表/视图/组合不是一种选择(如其他相关问题中所建议的那样)。
The rowversion
value is generated when a table with a rowversion
(aka timestamp
) value is modified. rowversion
值是在修改具有rowversion
(又名timestamp
)值的表时生成的。 The rowversion
value is database-scoped and the last generated value can be retrieved via @@DBTS
. rowversion
值是数据库范围的,最后生成的值可以通过@@DBTS
检索。
Since the value is incremented only when a rowversion table is modified, I don't think you'll be able to use @@DBTS
to avoid the downtime.由于仅在修改 rowversion 表时才会增加该值,因此我认为您无法使用@@DBTS
来避免停机。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.