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 2000 Forums
 SQL Server Development (2000)
 sql- create a trigger that will determine whether a specific field was updated

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-11-19 : 07:56:42
Shelly writes "I need to write a trigger that will respond to an update statement. If a particular field was updated, I need to act on that info. How do I tell whether a particular field was updated or not?"

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2004-11-19 : 08:07:53
Just create an update trigger and use IF UPDATE (column)
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-11-19 : 08:22:49
Won;t IF UPDATE (column) return TRUE if the column is changed in ANY of the records passed to the trigger?

Perhaps

SELECT *
FROM MyTable T
LEFT OUTER JOIN deleted D
ON D.MyPK = T.MyPK
WHERE D.MyPK IS NULL -- New record
OR T.MyColumn <> D.MyColumn
OR (T.MyColumn IS NULL AND D.MyColumn IS NOT NULL)
OR (T.MyColumn IS NOT NULL AND D.MyColumn IS NULL)

is needed to identify rows that a change in that specific column

Note that this will catach a new record where MyColumn = NULL - which maynot be required

Kristen
Go to Top of Page
   

- Advertisement -