简体   繁体   English

如何设置带有修订的自动增量主键的表结构?

[英]How do you setup table structure for auto increment primary key with revision?

C# interface accessing Sql server db. C#接口访问Sql Server数据库。

I have a table with a composite key ID and revision. 我有一个带有组合键ID和修订版的表。

When I "insert" a new record I want to auto increment the ID. 当我“插入”新记录时,我想自动增加ID。 When I "update" the record I want to actually insert a new record but increment revision. 当我“更新”记录时,我想实际插入一个新记录,但增加修订。

What is the proper table settings for this? 正确的表格设置是什么?

What I have done in the past is actually use a trigger for UPDATE . 我过去所做的实际上是使用UPDATE触发器。 It would copy all the values into a new record and increment the version column. 它将所有值复制到新记录中,并增加版本列。 I would also have an indexed column that would serve as a key, but not a primary key so that all revisions would be tied together. 我还将拥有一个索引列,该索引列将用作键,而不是主键,以便将所有修订版本捆绑在一起。

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

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