T-SQL Insert into table without having to specify every column

后端 未结 7 2518
悲&欢浪女
悲&欢浪女 2021-02-18 13:25

In our db there is a table that has a little over 80 columns. It has a primary key and Identity insert is turned on. I\'m looking for a way to insert into this table every colum

7条回答
  •  花落未央
    2021-02-18 14:02

    You can do this quite easily actually:

    -- Select everything into temp table
    Select * Into 
        #tmpBigTable
        From [YourBigTable]
    
    -- Drop the Primary Key Column from the temp table  
    Alter Table #tmpBigTable Drop Column [PrimaryKeyColumn]
    
    -- Insert that into your other big table
    Insert Into [YourOtherBigTable]
        Select * From #tmpBigTable
    
    -- Drop the temp table you created
    Drop Table #tmpBigTable
    

    Provided you have Identity Insert On in "YourOtherBigTable" and columns are absolutely identical you will be okay.

提交回复
热议问题