如何“创建表格(select * from)”

时间:2021-10-22 12:54:37

I want to use data from the existing table and create a new table using it. I am using local database (.mdf) file to store my data.

我想使用现有表中的数据并使用它创建一个新表。我使用本地数据库(.mdf)文件来存储我的数据。

I am not able to execute the following line:

我无法执行以下行:

SqlCommand com = 
           new SqlCommand("create table newinfo as (select * from oldinfo)", connection);

Is there any alternative way to create a table in C# from the data selected from another table.

是否有其他方法可以从另一个表中选择的数据中在C#中创建表。

2 个解决方案

#1


4  

You can use SELECT INTO:

您可以使用SELECT INTO:

SELECT * INTO YourNewTable FROM YourOldTable

See more here: https://technet.microsoft.com/en-us/magazine/dd401720.aspx

在此处查看更多信息:https://technet.microsoft.com/en-us/magazine/dd401720.aspx

#2


0  

To create a table from a select statement you use the following syntax

要从select语句创建表,请使用以下语法

SELECT Field1, Field2, Field3
INTO NewTable
FROM ExistingTable

#1


4  

You can use SELECT INTO:

您可以使用SELECT INTO:

SELECT * INTO YourNewTable FROM YourOldTable

See more here: https://technet.microsoft.com/en-us/magazine/dd401720.aspx

在此处查看更多信息:https://technet.microsoft.com/en-us/magazine/dd401720.aspx

#2


0  

To create a table from a select statement you use the following syntax

要从select语句创建表,请使用以下语法

SELECT Field1, Field2, Field3
INTO NewTable
FROM ExistingTable