Using trigger to set timestamp in SQL 2005

Hi,
I have followed the suggestions posted on this and created a trigger to set the datetime stamp in my table when
the record is added or modified. However, the datetime stamp is applied to all of the records in the table and not
just the record that has been modified.
What am I doing wrong? Could someone please help?
here is the trigger code.
CREATE TRIGGER [dbo].[updateTimeStamp] ON [dbo].[tblArchivedRecords]
FOR INSERT,UPDATE
AS
BEGIN

      SET NOCOUNT ON;
UPDATE tblArchivedRecords SET [TimeStamp] = GETDATE()


END
HarterAsked:
Who is Participating?
 
bmatumburaCommented:
Replace the .ID with your primary key field in both t.ID and inserted.ID
0
 
bmatumburaCommented:

CREATE TRIGGER [dbo].[updateTimeStamp] ON [dbo].[tblArchivedRecords]
FOR INSERT,UPDATE
AS
BEGIN
 
      SET NOCOUNT ON;
UPDATE tblArchivedRecords SET [TimeStamp] = GETDATE() FROM tblArchivedRecords t INNER JOIN inserted i ON t.ID = i.ID
 
 
END

Open in new window

0
 
HarterAuthor Commented:
thanks
that worked
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.