Is there a quick and easy way to have a datetime column in a table that will catch 'lastupdated' date and time. I can do this for 'inserted'/'created' by having a datetime column with a default value of getdate(), but is there a trick to do the same for updated.
ie
create table1
( test vachar(1),
created_date datetime default getdate(),
update_date datetime,
)
and have 'updated_date' column updated each time an update is made to the table.
I presume I require an update trigger, but how do I populate the updated_date column within the update trigger- any thoughts. Or is there another way.
Please no-one mention timestamp - I know all about that and it doesnt do what it says on the tin
thanks
KD
1. Stored Procedure layer -- require your updates to occur via a stored procedure that includes coding to automatically update the date. While, that may seem overkill, there are lots of other advantages to that approach; many practitioners consider it a best practice.
2. Update trigger. Technically, an "INSTEAD OF" trigger is proper because it avoids nested triggers. In the trigger you just issue an update statement for all rows that appear in the inserted table.