从Azure中的现有表创建空SQL表

时间:2022-02-23 02:01:48

I would like to create a new empty table by copying the structure of an existing table without copying any of the records. I am using SQL Azure.

我想通过复制现有表的结构而不复制任何记录来创建一个新的空表。我正在使用SQL Azure。

Attempt 1:

SELECT * INTO newTable
FROM oldTable
WHERE 1 = 0

Returns error:

Msg 40510, Level 16, State 1, Line 1
Statement 'SELECT INTO' is not supported in this version of SQL Server.

Attempt 2:

CREATE TABLE newTable
AS (SELECT * FROM oldTable WHERE 1=0)

Returns error:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.

Third time lucky? Have I missed something obvious, I am out of ideas.

第三次幸运?我是否错过了一些明显的东西,我没有想法。

UPDATE: In the end I performed this procedure:

更新:最后我执行了这个程序:

  • Added Azure table as linked table in Access mdb
  • 在Access mdb中将Azure表添加为链接表

  • Copied structure-only to local table
  • 仅将结构复制到本地表

  • Renamed table
  • Exported to Azure using 'SQL Server Import and Export Wizard'
  • 使用“SQL Server导入和导出向导”导出到Azure

2 个解决方案

#1


1  

As you've seen SELECT INTO isn't supported in Azure SQL Database. If the destination table already exists, then you can use INSERT INTO to populate it. See Kevin Yu's post on that: http://blog.kevinyu.org/2012/06/workaround-for-select-into-in-sql-azure.html.

正如您所见,Azure SQL数据库不支持SELECT INTO。如果目标表已存在,则可以使用INSERT INTO填充它。请参阅Kevin Yu的帖子:http://blog.kevinyu.org/2012/06/workaround-for-select-into-in-sql-azure.html。

I believe the issue of why SELECT INTO isn't supported is because every table in SQL Azure must have a clustered index. The SELECT INTO syntax would produce a table without a clustered index.

我认为不支持SELECT INTO的原因是因为SQL Azure中的每个表都必须具有聚簇索引。 SELECT INTO语法将生成一个没有聚簇索引的表。

This is an open connect issue for this at: http://connect.microsoft.com/SQLServer/feedback/details/776409/add-select-into-to-sql-azure

这是一个开放的连接问题:http://connect.microsoft.com/SQLServer/feedback/details/776409/add-select-into-to-sql-azure

I do not believe there is a good way to do this without first creating the destination table with a clustered index defined.

如果没有首先创建定义了聚簇索引的目标表,我不相信有一个好方法可以做到这一点。

#2


2  

SQL Azure requires that all tables have clustered indexes therefore you can't simply clone table structure without creating indexes.

SQL Azure要求所有表都具有聚簇索引,因此您无法在不创建索引的情况下简单地克隆表结构。

#1


1  

As you've seen SELECT INTO isn't supported in Azure SQL Database. If the destination table already exists, then you can use INSERT INTO to populate it. See Kevin Yu's post on that: http://blog.kevinyu.org/2012/06/workaround-for-select-into-in-sql-azure.html.

正如您所见,Azure SQL数据库不支持SELECT INTO。如果目标表已存在,则可以使用INSERT INTO填充它。请参阅Kevin Yu的帖子:http://blog.kevinyu.org/2012/06/workaround-for-select-into-in-sql-azure.html。

I believe the issue of why SELECT INTO isn't supported is because every table in SQL Azure must have a clustered index. The SELECT INTO syntax would produce a table without a clustered index.

我认为不支持SELECT INTO的原因是因为SQL Azure中的每个表都必须具有聚簇索引。 SELECT INTO语法将生成一个没有聚簇索引的表。

This is an open connect issue for this at: http://connect.microsoft.com/SQLServer/feedback/details/776409/add-select-into-to-sql-azure

这是一个开放的连接问题:http://connect.microsoft.com/SQLServer/feedback/details/776409/add-select-into-to-sql-azure

I do not believe there is a good way to do this without first creating the destination table with a clustered index defined.

如果没有首先创建定义了聚簇索引的目标表,我不相信有一个好方法可以做到这一点。

#2


2  

SQL Azure requires that all tables have clustered indexes therefore you can't simply clone table structure without creating indexes.

SQL Azure要求所有表都具有聚簇索引,因此您无法在不创建索引的情况下简单地克隆表结构。