“select * into table” Will it work for inserting data into existing table

后端 未结 4 1997
面向向阳花
面向向阳花 2021-02-05 10:58

I am trying to insert data from one of my existing table into another existing table.

Is it possible to insert data into any existing table using select * into

相关标签:
4条回答
  • 2021-02-05 11:11

    No, you cannot use SELECT INTO to insert data into an existing table.

    The documentation makes this very clear:

    SELECT…INTO creates a new table in the default filegroup and inserts the resulting rows from the query into it.

    You generally want to avoid using SELECT INTO in production because it gives you very little control over how the table is created, and can lead to all sorts of nasty locking and other performance problems. You should create schemas explicitly and use INSERT - even for temporary tables.

    0 讨论(0)
  • 2021-02-05 11:13

    Update from CTE? http://www.sqlservercentral.com/Forums/Topic629743-338-1.aspx

    0 讨论(0)
  • 2021-02-05 11:14

    You should try

    INSERT INTO ExistingTable (Columns,..)
    SELECT Columns,...
    FROM OtherTable
    

    Have a look at INSERT

    and SQL SERVER – Insert Data From One Table to Another Table – INSERT INTO SELECT – SELECT INTO TABLE

    0 讨论(0)
  • 2021-02-05 11:18

    @Ryan Chase Can you do this by selecting all columns using *? Yes!

    INSERT INTO yourtable2 SELECT * FROM yourtable1

    0 讨论(0)
提交回复
热议问题