Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Trigger


Trigger

Author
Message
gouripatil23
gouripatil23
SSC Journeyman
SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)

Group: General Forum Members
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
Andras Belokosztolszki
Andras Belokosztolszki
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1387 Visits: 1585
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
appala.naidu
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search