Writing a Single Trigger on Two Relations

  • 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

  • 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

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply