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

Update TABLE(B) because of changes made to TABLE(A) using trigger

Status
Not open for further replies.

brendasql

Programmer
Apr 1, 2003
58
US
This is my first experience with triggers so any help would be great. I am trying to figure out how to write a trigger that will update a column in Table(B) based on changes to a column in Table(A). I thought I should place the trigger on Table(A) and that the trigger should be something like this....(which I feel is totally wrong!)

IF Update(AColumn)
Update TableB
Set Bcolumn = '10'
Where AColumn = '1'

Please Help.
 
You're close I think. How are TableA and TableB related? There must be key column(s) in both tables. Your trigger will look something like this:

IF Update(AColumn)
Update TableB
Set Bcolumn = '10'
From Inserted
inner join TableB
on TableB.KeyColumn = Inserted.KeyColumn
Where inserted.AColumn = '1'

Inserted is a virtual table only available from within triggers. It contains the newly inserted or updated data. (FYI: The virtual table Deleted contains data before update or deleted rows.) Good luck!

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Thank you very very much John. It's working like a dream![smile2]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top