SQL Server RowVersion/时间戳 - 比较
我知道 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
列的表,则以下任一为真:
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"?
谢谢.
推荐答案
来自 MSDN:
每个数据库都有一个计数器,每次插入或更新操作都会增加一个计数器,该操作是在数据库中包含 rowversion
列的表上执行的.这个计数器是数据库rowversion
.这跟踪数据库中的相对时间,而不是可以与时钟关联的实际时间.每次行具有rowversion
列被修改或插入,递增> 数据库 rowversion
value 插入到 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
都应该是唯一的.我冒昧地说,如果在同一个表中允许重复,它们实际上将毫无用处.另外值得一提的是,rowversion
不被复制是 MSDN 不将它们用作主键的立场,不是因为它会导致违规,而是因为它会导致外键问题. - 根据 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.
相关文章