SQL Server RowVersion / Timestamp - 比较 [英] SQL Server RowVersion/Timestamp - Comparisons
问题描述
我知道 RowVersion
列的值本身不是有用的,除非它每次更新行时都会更改。
I know that the value itself for a RowVersion
column is not in and of itself useful, except that it changes each time the row is updated. However, I was wondering if they are useful for relative (inequality) comparison.
如果我有一个有 RowVersion $ c $的表格, c> column:
If I have a table with a RowVersion
column, are either of the following true:
- 同时发生的所有更新(同一更新语句或同一事务)在
RowVersion
列中有相同的值吗? - 如果我更新A,然后更新B在更新B中具有比更新A中涉及的行更高的值?
- Will all updates that occur simultaneously (either same update statement or same transaction) have the same value in the
RowVersion
column? - If I do update "A", followed by update "B", will the rows involved in update "B" have a higher value than the rows involved in update "A"?
$ b
推荐答案
从MSDN :
From MSDN:
每个数据库的计数器对于每次插入或更新在数据库中包含 rowversion
列的表。这个计数器是数据库 rowversion
。这跟踪数据库中的相对时间,而不是跟时钟相关联的实际时间。 每次已修改或插入 在 rowversion
列中插入增量数据库 rowversion
Each database has a counter that is incremented for each insert or update operation that is performed on a table that contains a rowversion
column within the database. This counter is the database rowversion
. This tracks a relative time within a database, not an actual time that can be associated with a clock. Every time that a row with a rowversion
column is modified or inserted, the incremented database rowversion
value is inserted in the rowversion
column.
http://msdn.microsoft.com /en-us/library/ms182776.aspx
- 据我所知,系统中没有同时发生的动作。这意味着所有
rowversion
s应该是唯一的。我冒昧地说,如果在同一个表内允许重复,它们实际上是无用的。还给予rowversion
不重复的信任是MSDN的不使用它们作为主键的立场,不是因为它会导致违反,而是因为它会导致外键问题。 li>
- 根据MSDN,rowversion数据类型只是一个递增的数字...所以是,后来更大。
- As far as I understand, nothing ACTUALLY happens simultaneously in the system. This means that all
rowversion
s should be unique. I venture to say that they would be effectively useless if duplicates were allowed within the same table. Also giving credance torowversion
s not being duplicated is MSDN's stance on not using them as primary keys not because it would cause violations, but because it would cause foreign key issues. - According to MSDN, "The rowversion data type is just an incrementing number..." so yes, later is larger.
对于增加的问题,MSDN指出:[ rowversion
]跟踪数据库中的相对时间这表示它不是一个流体整数递增,而是基于时间。但是,这个时间在确切时不显示任何内容,而是在相对于其他行插入/修改行。
To the question of how much it increments, MSDN states, "[rowversion
] tracks a relative time within a database" which indicates that it is not a fluid integer incrementing, but time based. However, this "time" reveals nothing of when exactly, but rather when in relation to other rows a row was inserted/modified.
这篇关于SQL Server RowVersion / Timestamp - 比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!