IF UPDATE (column)
Tests for an INSERT or UPDATE action to a specified column and is not used with DELETE operations. More than one column can be specified. Because the table name is specified in the ON clause, do not include the table name before the column name in an IF UPDATE clause. To test for an INSERT or UPDATE action for more than one column, specify a separate UPDATE(column) clause following the first one.
UPDATE(column) can be used anywhere inside the body of the trigger.
column
Is the name of the column to test for either an INSERT or UPDATE action. This column can be of any data type supported by SQL Server. For more information, IF (COLUMNS_UPDATED())
Tests, in an INSERT or UPDATE trigger only, whether the mentioned column or columns were inserted or updated. COLUMNS_UPDATED returns a 
varbinary bit pattern that indicates which columns in the table were inserted or updated.
COLUMNS_UPDATED can be used anywhere inside the body of the trigger.

解决方案 »

  1.   

    COLUMNS_UPDATED() 返回一个int值,相应位是1表示该列UPDATED。我觉得比较难用,每次写trigger都要试,不如用IF UPDATE (column)。
    下例在表 my_table 中创建名为 my_trig 的 INSERT 触发器,并测试列 b 是否受到任何 INSERT 语句的影响。CREATE TABLE my_table*
    (a int NULL, b int NULL)
    GOCREATE TRIGGER my_trig
    ON my_table
    FOR INSERT
    AS
    IF UPDATE(b)
       PRINT 'Column b Modified'
    GO下例使用 COLUMNS_UPDATED() 。CREATE TRIGGER my_trig2
    ON my_table
    FOR INSERT
    AS
    IF ( COLUMNS_UPDATED() & 2 = 2 )
       PRINT 'Column b Modified'
    GO