January 11, 2008 at 4:40 am
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
January 11, 2008 at 4:55 am
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
July 22, 2010 at 1:17 am
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 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply