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

Update trigger 1

Status
Not open for further replies.

Delphin

Programmer
Nov 27, 2001
134
US
I am off to learning triggers and the first one I am having an issue with. If I update 1 row, this works fine, however if I update more than one row only the last row updates. How do I get this to update all of the rows that were affected?

CREATE trigger TimeRetrieve
on trig
for update
as
if update (update1)
begin
declare @PK as int
select @PK = ID from inserted
update trig set times = getdate() where ID = @PK
end

Billy Ballard

For in the past, Lies the future.
 
Your @PK variable can only be filled with a single ID value. Try this:
if update (update1)
begin
update trig set times = getdate() from trig, inserted i where trig.ID = i.ID
end
 
Thank you very much. I have so much to learn

Billy Ballard

For in the past, Lies the future.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top