Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
To create History table to record changes in fields
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01135878
Message ID:
01135890
Views:
15
From "Programming Triggers" section of SQL BOL...
Testing for Changes to Specific Columns
The IF UPDATE (column_name) clause in the definition of a trigger can be used to 
determine if an INSERT or UPDATE statement affected a specific column in the table. 
The clause evaluates to TRUE whenever the column is assigned a value.
...
Alternatively, the IF COLUMNS_UPDATED() clause can be used to check which columns in 
a table were updated by an INSERT or UPDATE statement. This clause uses an integer 
bitmask to specify the columns to test. For more information, see CREATE TRIGGER.

Examples
A. Use the IF UPDATE clause to test data modifications
This example creates an INSERT trigger my_trig on table my_table and tests whether column b was affected by any INSERT statements.

CREATE TABLE my_table*
(a int NULL, b int NULL)
GO

CREATE TRIGGER my_trig
ON my_table
FOR INSERT
AS
IF UPDATE(b)
   PRINT 'Column b Modified'
GO
Kurt
>I want to create a history table for an existing table. This existing table has more then 250 fields. I want to enter a new row in the history table giving info like..which field is changed, old_value, new_value and date when changed.One of the way is to use trigger but how to find out which field changed. I want to use only SQL server and no programming language....Any information is highly appreciated.
>
>Thanks
>Bharat
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform