March 3, 2009 at 1:36 pm
when an insert happens in one table and i need to trigger that same insert into another table how would i write a trigger to call my stored procedure.
March 3, 2009 at 1:47 pm
Unless you are doing special processing you should be able to code the trigger for multi-row changes...
If you are using an stored procedure to insert on the first table you should add the extra insert on that same stored procedure and avoid the trigger altogether.
* Noel
March 3, 2009 at 1:52 pm
but the trigger should only run when the first table is inserted into. So it has to wait til something happens
March 3, 2009 at 2:40 pm
Paul, I believe noel's point is that if you have a stored procedure to insert rows into Table B, and you want to use it whenever you insert a row into Table A, you can just include the insert into Table B as part of the stored proc (presumably you have one) that inserts into table A. Pseudo-code follows:
StProcInsA
----------------------
INSERT INTO tableA
stProcInsB
----------------------
INSERT INTO tableB
Alter stProcInsA to
-------------------------
BEGIN TRAN
INSERT INTO tableA
EXEC stProcInsB
COMMIT TRAN
Now you have no need for a trigger, but the insert into Table B will run whenever the insert to Table A runs. However, if you are going to allow inserts into tableA from multiple procs or queries, then the trigger is the way to go.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply