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

Trigger firing for Inserting by Query

Status
Not open for further replies.

sammidiakreddy

Programmer
Feb 2, 2003
2
US
I have a trigger for Insert and Update on Table1 which updates or Inserts rows in Table2.
like
"
CREATE TRIGGER [Trigger1] ON [Table1]
FOR INSERT , UPDATE
AS
BEGIN
insert into Table2(Step, Executed) values ('r','1')
END
"
If I insert one row at a time the trigger is working fine.

But when I insert using a Query like
"insert into Table1 (Column1) select Column1 from table3",
the trigger is firing only one time

I have 75 rows in Table3, that means the trigger should Execute 75 times. that means I should Have 75 rows in Table2.

How can I make that trigger to execute for 75 times

 
The call to the trigger is made once once ,
but the inserted table contains the 75 records .

So use a cursor in a trigger to iterate these 75 rows and for each interation insert in Table2

Do a google on Row Level Triggers and Statement level triggers for more information.

Regards
Nikhil
 
NO do not use a cursor! Especially not in a trigger!!! Write a set-based insert using the inserted psuedotable?

Are your values ones from the table with the trigger? How are they related to table two?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top