Can we generate a trigger for two tables? if so what is the query to generate a trigger for two tables employee table and department table with employee having department no.

Showing Answers 1 - 27 of 27 Answers

sree

  • Jun 27th, 2006
 

We can't

In a trigger we can't specified two table name

that means

CREATE TRIGGER < > 
ON <{ table | view }> 

{
    { { FOR | AFTER | INSTEAD OF } { [ INSERT ] [ , ] [ UPDATE ] }
CREATE TRIGGER trigger_name
ON { table | view }
[ WITH ENCRYPTION ]

expecting justification on my answer

usha

  • Jul 18th, 2006
 

Yes, we can generate.

I am giving u one example

CREATE TRIGGER trg_SampleINSERT ON dbo.SampleMainTable           
FOR INSERT           
AS           
   INSERT INTO temp_SampleTable SELECT * FROM INSERTED 

  Was this answer useful?  Yes

Raj Sekhar

  • Aug 17th, 2006
 

Can u explain  how it works,

 

  Was this answer useful?  Yes

mehmet eser

  • Aug 12th, 2007
 

create two triggers that call the same stored procedure.... pass the new and old arguments to the procedure.

  Was this answer useful?  Yes

jeet

  • Sep 18th, 2007
 

It is not possible to invoke procedure from trigger!

  Was this answer useful?  Yes

chihoo2003

  • Jan 9th, 2008
 

No we cannot generate trigger for two tables. If we want to fire the trigger for two table we can use nested trigger.
 
A trigger invoking another trigger is called as nested trigger. 

  Was this answer useful?  Yes

Usha G, your code is right but it only for first (SampleMainTable)   table and execute whn you insert a record in the SampleMainTable  tabe so its only for SampleMainTable  table

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions