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!

Update trigger

Status
Not open for further replies.

EM1107

IS-IT--Management
Apr 24, 2002
153
0
0
CA
I have created the following trigger to update the date field in my table. The problem I have is that when I update one row it update all the rows.

What I am doing wrong?


CREATE TRIGGER NEW_GETDATE1
ON dbo.PROFILE
FOR update
AS

DECLARE @MYDATE DATETIME

SELECT @MYDATE = (GETDATE())
UPDATE dbo.PROFILE
SET DOCUMENT_DATE = @MYDATE

GO
 
What do you mean?

The document_date is a column of the Profile table.

Are you proposing that I do a Join of the table on it self?
 
The reason why you need to join to the inserted table is so that you only update the records which were updated. Assuming your primary key is ProfileId you would do something like this:

UPDATE dbo.PROFILE
SET DOCUMENT_DATE = @MYDATE
From inserted i
Where Profile.ProfileID = i.ProfileID
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top