T-SQL: How can you create a table with SELECT?

后端 未结 3 1560
逝去的感伤
逝去的感伤 2021-02-05 02:31

In oracle, you can issue:

 create table foo as select * from bar;

What is the equivalent T-SQL statement?

3条回答
  •  攒了一身酷
    2021-02-05 02:41

    You can use SELECT INTO. From MSDN:

    The SELECT INTO statement creates a new table and populates it with the result set of the SELECT statement. SELECT INTO can be used to combine data from several tables or views into one table. It can also be used to create a new table that contains data selected from a linked server.

    So:

    SELECT col1, col2, col3 INTO newTable FROM existingTable;
    

提交回复
热议问题