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)
 trigger on update of only specific fields

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-09-25 : 03:05:21
is it possible to make a update trigger that only happens if specific fields are changed.
I have a table with many fields and I want to call the trigger if the startdate or enddate is changed but if any other field is changes I don't want to call it.
Is this possible?

Kabila
Starting Member

33 Posts

Posted - 2009-09-25 : 03:25:11
Yes it is possible.

if Update(Columnname)
Begin

End
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-09-25 : 03:34:41
so it would be 2 different triggers?
or if update(startdate) or update(enddate)
begin

end
Go to Top of Page

Kabila
Starting Member

33 Posts

Posted - 2009-09-25 : 03:55:28
No it is in single trigger.
You can use either

if update(startdate) or update(enddate)
begin
Print 'date updated'
end
---
or

if update(startdate)
begin
Print 'Startdateupdated'

end
if update(enddate)
begin
Print 'Enddate updated'
end
Go to Top of Page
   

- Advertisement -