Trigger

  • gouripatil23

    SSC Enthusiast

    Points: 174

    Hi!

    I want Update one table when in another table insert new record .I didn't understand how i get this new inserted ID.

    Regards

    Gouri

  • Andras Belokosztolszki

    SSC-Insane

    Points: 21921

    gouripatil23 (1/11/2008)


    Hi!

    I want Update one table when in another table insert new record .I didn't understand how i get this new inserted ID.

    Regards

    Gouri

    Hi Gouri,

    In the trigger body you have access to two virtual tables, inserted and deleted. These contain the data about the rows that you have inserted (or deleted/modified). You can update the table you wish based on the inserted table. See http://msdn2.microsoft.com/en-us/library/ms189799.aspx

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • appala.naidu

    Grasshopper

    Points: 15

    The below code may help u in finding ur problem

    set ANSI_NULLS ON

    set QUOTED_IDENTIFIER ON

    GO

    -- =============================================

    -- Author: <Author,,Name>

    -- Create date: <Create Date,,>

    -- Description: <Description,,>

    -- =============================================

    ALTER TRIGGER [dbo].[Insert_Trg_Dept]

    ON [dbo].[Dept]

    AFTER INSERT

    AS

    BEGIN

    SET NOCOUNT ON;

    DECLARE

    @EMPID INT,

    @DEPTID INT,

    @DEPTNAME VARCHAR(50)

    SELECT @EMPID=EMPID FROM EMPLOYEE

    INSERT INTO DEPT VALUES(@DEPTNAME,@DEPTID,@EMPID)

    END

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

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