SQL Server RowVersion/Timestamp - Comparisons(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
RowVersioncolumn? - 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
rowversions should be unique. I venture to say that they would be effectively useless if duplicates were allowed within the same table. Also giving credance torowversions 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/时间戳 - 比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server RowVersion/时间戳 - 比较
- 更改自动增量起始编号? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- SQL 临时表问题 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
