Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
To create History table to record changes in fields
Message
From
15/07/2006 02:40:24
 
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01135878
Message ID:
01136630
Views:
10
Hi, Bharat,

First, again, I recommend against using the UPDATE function, which will only tell you if a column is specified in an UPDATE statement. If I repeatedly issue the command...
UPDATE MyTable SET FirstName = 'Kevin'
...the UPDATE function will return a true for the firstname column, every time. You need to join the Inserted and Deleted columns to see if something truly "changed".

Also, I'm not sure if your code is going to work if a single UPDATE affects multiple rows. In SQL Server, an update trigger fires one per UPDATE statement. So make sure your code will handle an UPDATE that affect multiple rows.

The code you posted may "work", but will be compartively more difficult to manage. Imagine how complicated your logic will become once you start to add more and more columns to the mix.

You're probably better off reearching update triggers and doing some more reading, to get a stronger handle on how to manage something like this. If you're saying you're not that good at writing scripts, fine - but I would suggest you invest some time and make yourself better at it.

Kevin
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform