Update trigger GetDate() on Indexed

I have a table with a DateTime field called "stamp".  The default value is already set for (GetDate()) on insert of new records and wrks fine.
I need that "stamp" field to get updated with GetDate() when that particular record/index is updated.

How can this be done.  I would prefer not to use any history/temp table method here.
LVL 1
H-SCAsked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
create trigger tr_u_TableName
on table_name
after insert, update
as
 update t
 set datecolumn = GETDATE()
 from tableName t
 inner join inserted i on t.Primarykey = i.primarykey
0
 
H-SCAuthor Commented:
aneeshattingal,

Perfect!  Many thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.