Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Writing a Single Trigger on Two Relations Expand / Collapse
Author
Message
Posted Sunday, December 30, 2012 4:07 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, December 11, 2014 3:17 AM
Points: 206, Visits: 512
Dear,
I have an application running on my system. There is a certain module that if I click on 'Save' button, it inserts a row on Header & Detail tables. Now I want to write a single trigger on Header & Detail tables which will insert a row into 'Test' table.

How can I do this? Please help me.

Regards,
Akbar
Post #1401243
Posted Sunday, December 30, 2012 6:26 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, October 8, 2014 2:46 AM
Points: 55, Visits: 159
if you want to insert the data from the two tables (header and detail) to test table you can do something like this...

1. get the inserted value in dbo.inserted
2. join dbo.inserted and Header Table.


sample code below

CREATE TRIGGER Detail_Insert
ON detail
FOR INSERT
AS

insert into Detail_table
select I.id, * from dbo.inserted I
inner join header H
on I.id = H.Id


This code will work. Just make some neccessary adjustment as to what fields to you want
Post #1401246
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse