Insert all values of a table into another table in SQL

后端 未结 9 1013
礼貌的吻别
礼貌的吻别 2020-11-29 16:56

I am trying to insert all values of one table into another. But the insert statement accepts values, but i would like it to accept a select * from the initial_Table. Is this

9条回答
  •  没有蜡笔的小新
    2020-11-29 17:29

    There is an easier way where you don't have to type any code (Ideal for Testing or One-time updates):

    Step 1

    • Right click on table in the explorer and select "Edit top 100 rows";

    Step 2

    • Then you can select the rows that you want (Ctrl + Click or Ctrl + A), and Right click and Copy (Note: If you want to add a "where" condition, then Right Click on Grid -> Pane -> SQL Now you can edit Query and add WHERE condition, then Right Click again -> Execute SQL, your required rows will be available to select on bottom)

    Step 3

    • Follow Step 1 for the target table.

    Step 4

    • Now go to the end of the grid and the last row will have an asterix (*) in first column (This row is to add new entry). Click on that to select that entire row and then PASTE (Ctrl + V). The cell might have a Red Asterix (indicating that it is not saved)

    Step 5

    • Click on any other row to trigger the insert statement (the Red Asterix will disappear)

    Note - 1: If the columns are not in the correct order as in Target table, you can always follow Step 2, and Select the Columns in the same order as in the Target table

    Note - 2 - If you have Identity columns then execute SET IDENTITY_INSERT sometableWithIdentity ON and then follow above steps, and in the end execute SET IDENTITY_INSERT sometableWithIdentity OFF

提交回复
热议问题