Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I need to implement a trigger which triggers when an insert occurs in table A. At the same time I also want to copy this inserted data into another table B.

How can I do that?

Please help me.

Thanks in Advance.
Posted
Updated 13-Jun-11 2:15am
v3
Comments
Prasad CM 13-Jun-11 8:28am    
What are the Columns in Table A

Here is the Solution

SQL
CREATE Trigger trg_A
ON A
FOR INSERT
AS

Begin

Declare @Col1 int, @Col2 varchar(20)

Select 
@Col1=i.col1,
@Col2=i.col2
FROM Inserted i

INSERT INTO B VALUES(@Col1,@Col2)

End
 
Share this answer
 
v4
Start here[^]. You should try and work something out for yourself before posting here and tell us what it is you have done to help yourself, what issues you came up against, etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900