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

Trigger Expand / Collapse
Author
Message
Posted Friday, January 11, 2008 4:40 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, December 11, 2009 5:20 AM
Points: 78, Visits: 35
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
Post #441663
Posted Friday, January 11, 2008 4:55 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 26, 2012 5:26 AM
Points: 1,367, Visits: 1,585
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
Post #441667
Posted Thursday, July 22, 2010 1:17 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 23, 2010 6:54 AM
Points: 1, Visits: 1
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
Post #956964
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse