GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Database  >  SQL Server
Go To First  |  Previous Question  |  Next Question 
 SQL Server  |  Question 36 of 99    Print  
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.

  
Total Answers and Comments: 11 Last Update: February 03, 2008     Asked by: laxman 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: sree
 

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



Above answer was rated as good by the following members:
jayanthan2006, kisudocp
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
June 27, 2006 14:44:58   #1  
sree        

RE: can we generate a trigger for two tables? if so wh...

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


 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
July 18, 2006 03:31:54   #2  
usha        

can we generate a trigger for two tables? if so wh...

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


 
Is this answer useful? Yes | No
August 17, 2006 05:54:52   #3  
Raj Sekhar        

RE: can we generate a trigger for two tables? if so wh...

Can u explain how it works


 
Is this answer useful? Yes | No
February 25, 2007 23:44:18   #4  
sarakumar Member Since: February 2007   Contribution: 1    

RE: Can we generate a trigger for two tables? if so wh...
i think we can achieve this by using nested triggers.but i never tried this.
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
August 12, 2007 14:43:26   #5  
mehmet eser        

RE: Can we generate a trigger for two tables? if so wh...
create two triggers that call the same stored procedure.... pass the new and old arguments to the procedure.
 
Is this answer useful? Yes | No
September 18, 2007 07:23:24   #6  
jeet        

RE: Can we generate a trigger for two tables? if so wh...
It is not possible to invoke procedure from trigger!
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
November 12, 2007 02:26:34   #7  
sivaji Member Since: October 2007   Contribution: 2    

Can we generate a trigger for two tables? if so wh...
Usha u can give to commands how it's works can u explain ?
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
January 04, 2008 04:30:03   #8  
chauhan_anilit Member Since: October 2007   Contribution: 8    

RE: 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.
Usha Mam can u tell me how this code work. ?
 
Is this answer useful? Yes | No
January 09, 2008 15:02:00   #9  
chihoo2003 Member Since: January 2008   Contribution: 4    

RE: 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.
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.

 
Is this answer useful? Yes | No
January 10, 2008 00:09:33   #10  
chauhan_anilit Member Since: October 2007   Contribution: 8    

RE: 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.
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
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape