[英]Excluding column from T-SQL RowVersion update
I have a database table in SQL Server that I am using T-SQL's RowVersion
to record a GenerationNumber
and detect have any records changed. 我在SQL Server中有一个数据库表,该数据库表使用T-SQL的RowVersion
记录GenerationNumber
并检测是否有任何记录更改。 This paradigm has worked successfully for my application, but now I want to add a column that does not increment the RowVersion
column on UPDATE
. 此范例已成功地为我的应用程序工作,但现在我想添加一个不会增加UPDATE
上的RowVersion
列的列。
Is there any way of excluding a column from the RowVersion
increment? 有什么办法从RowVersion
增量中排除一列? Or should I change the datatype of RowVersion
to a datetime
and handle it myself in a trigger? 还是应该将RowVersion
的数据类型更改为datetime
,然后自己在触发器中处理它?
Any suggestions or ideas are welcome 欢迎任何建议或想法
If you currently have a table T
- rename it as something like T_Tracked
and introduce a second table T_Untracked
that has a FK back to the first table. 如果您当前有一个表T
,则将其重命名为T_Tracked
类的T_Tracked
然后引入第二个表T_Untracked
,该表的FK返回第一个表。
Then introduce a view, T
, that joins these tables together. 然后引入视图T
,将这些表连接在一起。 Your application continues to reference T
. 您的应用程序继续引用T
You then put your "trigger-writing" hat on and write appropriate triggers on this view to ensure that both tables are populated during an insert
, both are deleted from during delete
and only the applicable tables are updated during an update
. 然后你把你的“触发写作”的帽子上写适当的触发这一观点,以确保这两个表的过程中填充insert
,无论是从过程中被删除delete
,只适用表的过程中更新update
。
That way it appears to still be a rowversion
column but updates that only affect T_Untracked
will not cause it to be changed. 这样,它似乎仍然是rowversion
列,但是仅影响T_Untracked
更新不会导致对其进行更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.