oracle T-SQL:如何使用 SELECT 创建表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2224280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 02:23:13  来源:igfitidea点击:

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

oracletsql

提问by chris

In oracle, you can issue:

在 oracle 中,您可以发出:

 create table foo as select * from bar;

What is the equivalent T-SQL statement?

什么是等效的 T-SQL 语句?

回答by Oded

You can use SELECT INTO. From MSDN:

您可以使用SELECT INTO. 来自 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.

SELECT INTO 语句创建一个新表并用 SELECT 语句的结果集填充它。SELECT INTO 可用于将来自多个表或视图的数据合并到一个表中。它还可用于创建包含从链接服务器中选择的数据的新表。

So:

所以:

SELECT col1, col2, col3 INTO newTable FROM existingTable;

回答by CaffGeek

You can try like this:

你可以这样试试:

select * into foo from bar

回答by scarpacci

If you want to write to the tempdb

如果要写入 tempdb

Select *
INTO #tmp
From bar

or to a SQL DB

或到 SQL 数据库

Select *
INTO Temp
From bar