Home > Archive > MS SQL Server > March 2006 > trigger for Inserting question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author trigger for Inserting question
Jason Huang

2006-03-15, 3:23 am

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


Tibor Karaszi

2006-03-15, 3:23 am

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.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www. solidqualitylearning
.com/



"Jason Huang" < JasonHuang8888@hotma
il.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
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com