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

Update Trigger Syntax

Status
Not open for further replies.

btturner

Programmer
May 17, 2001
175
US
The following TRIGGER is firing and UPDATING "ALL" rows my table. How can I modify the SQL UPDATE portion to ONLY update the row being UPDATED?

create trigger trgu_Customer on Customer for update as
begin
if update (Telephone_Number)
update Customer set touchdate = (select getdate())
end

thx in advance..
 
I assume that the customer table have some unique column e.g. customerid.

Code:
create trigger trgu_Customer on Customer for update as
begin
 if update (Telephone_Number)
  update Customer set touchdate = getdate()
   where customerid in (select customerid from inserted)
end

The inserted table contains all rows that are affected by the query.
 
This must be trigger day, I just answered this exact question. See the trigger below for an example, it does assume you have some kind of identifying field (in this case called RecordID) in the table:

Create Trigger Update_Dates
On Table1
For Update
AS
Update Table1
set Update_Date = GetDate()
from Table1, inserted
where table1.REcordID = inserted.RecordID
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top