How to insert data into two tables using signle SQL Query.

  • Hi 🙂 ,

    Can any one suggest me ,

    How to insert data into two tables using single SQL Query with out using Stored procedure

    😛

  • You need to create View & INSTEAD OF trigger to achieve the desired result.

    search "INSTEAD OF triggers" in SQL Server books online - it has more details as well as example.

    Thanks

  • ALTER TRIGGER INSERTTRIGGER ON dbo.opportunitybase

    AFTER INSERT

    AS

    BEGIN

    DECLARE @Operation int

    DECLARE @opp_Name varchar(100)

    DECLARE @EstiCloseValue varchar(100)

    DECLARE @Opp_id uniqueidentifier

    SET @opp_Name = (SELECT NAME FROM INSERTED)

    SET @EstiCloseValue = (SELECT ModifiedOn FROM INSERTED)

    SET @Opp_id = (SELECT opportunityid FROM INSERTED)

    INSERT INTO UserTrigger (Name,EstiDate,oppid,flag) values (@opp_name,@EstiCloseValue , @Opp_id,'I')

    END

    ** Iam inserting the values into the table named "opportunitybase"

    ** Then using trigger iam inserting the same values inot another table named "UserTrigger "

    I hope this will solve ur problem

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

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