Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I wants to insert the values of one table to another by using trigger. the columns are same for both the tables and i wanna insert values. how would I?
Posted

1 solution

The answer to your question is YES, you can do it using trigger. You will have to use the Insert trigger for this.

Code :
SQL
CREATE TRIGGER triggerName ON yourSourcetable FOR INSERT
AS

    INSERT INTO yourDestinationTable
        (col1, col2    , col3)
    SELECT
        'value1', 'value2', 'value3'
        FROM inserted

GO


when you want to access the new record which is being inserted then the same can be accessed using system table name inserted. I have used this table only. So you can replace the names of the columns by your table's columns.

Hope this helps.
All the best.
 
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