简体   繁体   English

向表中添加 rowversion 列并对现有数据进行排序

[英]Adding a rowversion column to a table and ordering existing data

I want to add a rowversion column to an existing table in my database so I can essentially order by the last time each record was modified successfully.我想在我的数据库中的现有表中添加一个 rowversion 列,这样我基本上可以按上次成功修改每条记录的时间进行排序。 My question is, how will adding the rowversion affect my existing data?我的问题是,添加 rowversion 将如何影响我现有的数据? Will the rowversion values be assigned like random on these records or by the last instance they were modified too? rowversion 值是在这些记录上随机分配还是在最后一次修改时分配? (Even though they existed before the column) (即使它们存在于列之前)

My question is, how will adding the rowversion affect my existing data?我的问题是,添加 rowversion 将如何影响我现有的数据?

You can test it.你可以测试一下。

eg例如

drop table if exists t
go
create table t(id int primary key)
insert into t(id) values (1),(2),(3)
go
alter table t add rv rowversion

go
insert into t(id) values (4)

insert into t(id) values (5),(6)

go
select * from t

outputs产出

(3 rows affected)

(1 row affected)

(2 rows affected)
id          rv
----------- ------------------
1           0x00000000000007DD
2           0x00000000000007DE
3           0x00000000000007DF
4           0x00000000000007E0
5           0x00000000000007E1
6           0x00000000000007E2

(6 rows affected)

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

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