[英]SQL Server : detect column changes
I am trying to detect any changes in a column.我正在尝试检测列中的任何更改。 Let me describe my problem exactly.让我准确地描述我的问题。
Let's say I have 400 stored procedures and 20 of them changes a column named ModDate
in a table Users
.假设我有 400 个存储过程,其中 20 个更改了表Users
名为ModDate
的列。 But the ModDate
column is not enough for me to achieve my goal.但是ModDate
列不足以让我实现我的目标。 I need a dirty bit column let's say IsChanged
.我需要一个脏位列让我们说IsChanged
。
My solution would be find and check the procedures that updates Users.ModDate
and change these procedures to update IsChanged
as well.我的解决方案是查找并检查更新Users.ModDate
的程序,并将这些程序更改为更新IsChanged
。 But this is not efficient in time.但这在时间上效率不高。 Also, I may miss some procedures and this will cause problems.另外,我可能会错过一些程序,这会导致问题。
So, my question;所以,我的问题; is it possible to alter a table/column to create an "on change" trigger?是否可以更改表/列以创建“更改时”触发器? When any procedure changes the value of Users.ModDate
, SQL Server will update the IsChanged
column as 1 automatically.当任何过程更改Users.ModDate
的值时,SQL Server 会自动将IsChanged
列更新为 1。
Thanks for your answers.感谢您的回答。
You can create a trigger on a column for different crud events.您可以为不同的 crud 事件在列上创建触发器。
See https://www.sqlservertutorial.net/sql-server-triggers/sql-server-create-trigger/见https://www.sqlservertutorial.net/sql-server-triggers/sql-server-create-trigger/
`CREATE TRIGGER [schema_name.]trigger_name ON table_name AFTER {[INSERT],[UPDATE],[DELETE]} [NOT FOR REPLICATION] AS {sql_statements`}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.