Is it possible to use a variable in UPDATE() which check if a column is updated or not?
here is my sample code:
DECLARE @ColumnCount int
DECLARE @ColumnC
to check for column is actually updated in after update trigger
you can use deleted
and inserted
special tables msdn in which trigger code can find old and new versions of rows of updating table
remember that it is possible to find there more than 1 row in each table. for example you execute update table1 set col1 = value1 where some_condition
in trigger number of rows affects by some_condition
, will be presented in inserted
and deleted
tables
to find out in trigger in what rows some column is actual updating, you can join inserted and deleted tables on some primary key and compare values of this column
the update()
function takes as parameter column name not a sting variable with name as value
for example using update()
in triggers check this update(some_column)
is true when some_column
present in update set
statement, even value of column not changing.
it seems like you can not write universal trigger to count number of columns updated, if you need that count you need to manually write trigger for each table with somethig like this
declare @count int = 0
if update(col1) set @count = @count + 1
if update(col2) set @count = @count + 1
...