尝试将数据库发布到没有聚簇索引的Azure时出错

时间:2013-10-13 16:20:43

标签: sql sql-server azure webmatrix

尝试将我的数据库发布到Azure网站时出现以下错误:

17:13:29: Could not publish the site. Unable to publish the database. For more information, see "http://go.microsoft.com/fwlink/?LinkId=205387"
17:13:29: Error detail:
17:13:29: An error occurred during execution of the database script. The error occurred between the following lines of the script: "332" and "334". The verbose log might have more information about the error. The command started with the following:
17:13:29: "INSERT [dbo].[DBStatus] ([LastIndex], [LastUpdated"
17:13:29:  Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again. http://go.microsoft.com/fwlink/?LinkId=178587
17:13:29:   Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_SQL_EXECUTION_FAILURE.

此链接说明错误:http://blogs.msdn.com/b/sqlazure/archive/2010/04/29/10004618.aspx

是否有一种简单的方法可以将我的数据库转换为具有聚簇索引,还是应该选择具有SQL Server 2012托管的主机?

2 个答案:

答案 0 :(得分:5)

我不会因此而更改您的托管选项。添加聚簇索引。

有一个名为SQL Database Migration Wizard的工具可以分析SQL数据库并制作迁移脚本甚至移动数据。它将做的一件事是建议没有它们的表上的聚簇索引。但是,像任何工具一样,请确保查看它的建议并查看它在您的方案中是否有意义。

我的建议是查看没有聚簇索引的表,并确定要创建的合理索引。像上面这样的工具可以提出建议,但它们只是建议,可能不完全是您的表格将从中受益。

对Azure SQL数据库的聚簇索引的要求来自于它们一式三份地复制数据,并且聚簇索引使得这一过程变得更快。

答案 1 :(得分:2)

我已经完成了以下步骤:

1-通过运行此查询获取没有主键的表列表:

USE DatabaseName;
GO

SELECT SCHEMA_NAME(schema_id) AS SchemaName,name AS TableName
FROM sys.tables
WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') = 0
ORDER BY SchemaName, TableName;
GO`

2-为所有表创建警报表脚本,为其添加一个标识字段,并通过以下脚本将其设为主要:

 ALTER TABLE [dbo].[tableName]  ADD identityFieldName BIGINT IDENTITY;  
 ALTER TABLE [dbo].[tableName]  ADD CONSTRAINT  PK_Table_identityFieldName_1    PRIMARY KEY CLUSTERED (identityFieldName);      

对所有没有主键的表格重复上述查询

相关问题