Home All Groups Group Topic Archive Search About

trigger for Inserting question



Author
15 Mar 2006 8:47 AM
Jason Huang
Hi,

In my SQL Server 2000, I want to create an Insert trigger.
If inserting into TableA, then it will also insert into TableB.
What will the solution be like?
Thanks for help.


Jason

Author
15 Mar 2006 9:04 AM
Tibor Karaszi
Here's a generic skeleton for such a trigger:

CREATE TRIGGER myTrigger ON TableA
AFTER INSERT
AS
IF @@ROWCOUNT = 0 RETURN
INSERT INTO TableB (col1, col2, ...)
SELECT col1, col2, ...
FROM inserted
GO

See Books Online, CREATE TRIGGER for more information.

Show quoteHide quote
"Jason Huang" <JasonHuang8***@hotmail.com> wrote in message
news:%236V5R0ASGHA.5552@TK2MSFTNGP14.phx.gbl...
> Hi,
>
> In my SQL Server 2000, I want to create an Insert trigger.
> If inserting into TableA, then it will also insert into TableB.
> What will the solution be like?
> Thanks for help.
>
>
> Jason
>

Bookmark and Share