Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with an update trigger

Status
Not open for further replies.

ghost2

Programmer
Aug 7, 2003
145
0
0
US
Can anyone give me the followin example for a trigger? I need to update a Last Modification Date in a table if any of four fields change values in that table. The value has to be different from the current value though in order for the trigger to fire. The ID is called SID in the table. Thanks all.
 
Below is an example of a trigger that I use to datestamp a table any time that any column in the table is updated. If you add a WHERE clause that compares the values of the column in TableName to INSERTED, you should be able to get what you need.

Code:
CREATE TRIGGER TableName_DateStampModifyDate
ON DbName.DBO.TableName
FOR UPDATE 
AS 
BEGIN
 UPDATE TableName
 SET MODIFYDATE = getDate()
 FROM TableName T INNER JOIN INSERTED I ON T.ID = I.ID
END

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top