Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help with trigger please

Author  Topic 

natenate
Starting Member

2 Posts

Posted - 2010-11-30 : 10:43:01
I need to write an update trigger that will set a column to getdate() if any of the other columns have been updated for that particular row. I know it would be an update trigger but have not figured out the syntax yet.

Can someone please give me an example?

It looks like i may need to use the inserted table but i have not figured that out yet.

thanks in advance

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-11-30 : 10:49:13
create triger on mytbl for update
as
update mytbl
set z_updated = getdate()
from mytbl t
join inserted i
on t.PK = i.PK
go

That will set the value for anything involved in the update statement.
Not - that doesn't mean that any column value has been changed - you would have to check each column individually for that.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

natenate
Starting Member

2 Posts

Posted - 2010-11-30 : 11:13:10
Thanks!
Go to Top of Page
   

- Advertisement -