How to Insert data from one table to Multiple tables

  • Assume I have One source table with 10 columns and I have 10 diffrent destination tables.

    each column in source table goes to or mapped to the columns in destination table.

    For Eg: source_table (tablename) have columns col1, col2,col3,clo4,col5

    Destination table names: Des_table1, Des_table2,Des_table3,Des_table4,Des_table5,

    Now How can I insert

    col1 from source_table to Des_table1 &

    col2 from source_table to Des_table2 and

    col3 from source_table to Des_table3 and so on.....

  • 1. In your stored procedure, use the output clause of your insert statement to put all inserted records into a temp table or table variable. Then insert the appropriate column from there to your desired location.

    2. Put an insert trigger on the table. In the trigger, insert into the appropriate table the appropriate column from the virtual inserted table.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply