Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 AFTER INSERT Trigger

Author  Topic 

Shilpa22
Starting Member

37 Posts

Posted - 2010-08-17 : 09:46:26
Hello Friends,

I have a Table1(10 columns) in which if a record is inserted, then immediately that same record needs to be inserted in Table2 with only 4 columns. I am new to this Trigger concept.
Please help/guide me with a sample Trigger.

THanks in Advance.


Thanks in Advance
Shilpa

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-08-17 : 09:53:32
Something like this
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[TABLEA_TRIG_INSERT]
ON [dbo].[TABLEA]
FOR INSERT
AS
BEGIN
INSERT INTO TABLEB
(
COL1,
COL2,
COL3,
COL4
)
SELECT
COL1,
COL2,
COL3,
COL4
FROM Inserted
END
Go to Top of Page

Shilpa22
Starting Member

37 Posts

Posted - 2010-08-18 : 02:34:41
Thank you vijayisonly. It resolved my issue.

Thanks in Advance
Shilpa
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-08-18 : 09:04:08
Np. You're welcome.
Go to Top of Page
   

- Advertisement -