2013-10-13 53 views
1

想我的數據庫發佈到我的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託管?

回答

5

因爲這個原因,我不會更改您的託管選項。添加聚簇索引。

有一個名爲SQL Database Migration Wizard的工具,可以分析SQL數據庫並製作遷移腳本甚至移動數據。它會做的一件事是在沒有它們的表上建議一個聚集索引。然而,像任何工具一樣,確保你看看它的建議,看看它在你的場景中是否有意義。

我的建議是查看沒有聚集索引的表並確定合理的索引來創建。像上面那樣的工具可以提出建議,但它們只是建議,可能並不完全適合您的表格。

對Azure SQL數據庫的聚集索引的要求來自於它們一式三份複製數據,並且聚集索引使得該過程更快。

+0

好建議+1。有關信息 - 現在可以使用V12預覽版(2015年1月),您可以創建沒有聚集索引的表。 http://azure.microsoft.com/en-gb/documentation/articles/sql-database-preview-whats-new/ – Colin

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);  

重複上述查詢所有表不具有主鍵