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

One Trigger to Rule them All

Status
Not open for further replies.

hexOffender

Programmer
Nov 6, 2006
146
US
Ok, not really, but I need a trigger to insert or update certain table whenever a few other tables are inserted or updated. For example, myTable should pull certain fields whenever table A,B,C,D are updated. Table A,B,C,D, all share a PK of VisitID. The problem, as I see it, is I don't know which table will be updated first, or have a new record added.
 
markros is right. You'll need to add a trigger to each table, and if the new record must exist in all 4 tables before writing to the 5th, then use an INNER JOIN of all 4 tables to do the update/insert to the 5th. Depending on how your data is structured, the INNER JOIN will not return a data set unless all 4 tables have a match.

Just a thought.

--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
 
Yeah I can see that i'll have to create one for each table.
I've already written 3 of them in the Test db. I think I got it now.
 
Alternative: use a stored procedure to create the records in all 4 tables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top