Depends on the level of reporting you need to do. If you just want to know when the record last last changed add a field called ModificationDate and have an update trigger fill it in when ever a record is updated. If you want to see when the record was created and compare to when it was updated, then as a CreateDate field and give it a default value of GetDate().
If you need to know exactly what was changed you need an update trigger to copy the old record to an audit table. Then you can compare the two records in a SQL query to see the differences. Of course this won't work unless you have some kind of unique record identifier on the original table. It is also helpful to use one of the username functions to get the name of the person making the change too. The audit table can get right large, so you may want to only copy records where a few specific important fields have changed.
How can you make a trigger only go when a certain column is updated? The below trigger will go anytime the table is updated but I want it to go only what the name column in the table is updated. Also, how can I get what was in the column before and after it was changed.
CREATE TRIGGER tbl1_TrackUpdates ON [dbo].[Table2]
FOR INSERT, UPDATE
AS
update [dbo].[Table2] set [LastUpdatedDate] = getdate(), [LastUpdatedBy] = USER_NAME()
All this info is in Books Online. Look up CREATE TRIGGER, especially the IF UPDATE() syntax to check which columns were updated and the "inserted" and "deleted" pseudo-tables which contain the data before and after the action.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.