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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger for time stamp

Status
Not open for further replies.

jldavis5

IS-IT--Management
Jan 22, 2002
9
US
Can someone show me a trigger that would insert a timestamp into a column of a record everytime that record was changed? Something like a last updated trigger.
 
Example:

CREATE TRIGGER rec_updated
ON MyTable
FOR INSERT, UPDATE
AS

set nocount on

Update MyTable
Set UpdtDatetime=getdate()
From MyTable
Join inserted
-- join assumes that a unique column
-- names RecId exists on the table
On MyTable.RecID=inserted.RecId

set nocount off
Go Terry L. Broadbent - Salt Lake City, UT
Home of the 2002 Winter Olympics (Feb 8-24)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top