Insert into … values ( SELECT … FROM … )

前端 未结 26 2429
我在风中等你
我在风中等你 2020-11-21 05:40

I am trying to INSERT INTO a table using the input from another table. Although this is entirely feasible for many database engines, I always seem to struggle t

26条回答
  •  借酒劲吻你
    2020-11-21 06:20

    Simple insertion when table column sequence is known:

        Insert into Table1
        values(1,2,...)
    

    Simple insertion mentioning column:

        Insert into Table1(col2,col4)
        values(1,2)
    

    Bulk insertion when number of selected columns of a table(#table2) are equal to insertion table(Table1)

        Insert into Table1 {Column sequence}
        Select * -- column sequence should be same.
           from #table2
    

    Bulk insertion when you want to insert only into desired column of a table(table1):

        Insert into Table1 (Column1,Column2 ....Desired Column from Table1)  
        Select Column1,Column2..desired column from #table2
           from #table2
    

提交回复
热议问题