如下測試例子以SQL 2008備份,在SQL2014還原,形成索引被禁用.sql
--備份環境(SQL Server 2008 R2)測試
/*ui
MicrosoftSQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64) spa
Apr 2 2010 15:48:46 code
Copyright (c) Microsoft Corporation對象
Data Center Edition (64-bit) on WindowsNT 6.1 <X64> (Build 7600: ) (Hypervisor)索引
*/it
--還原環境(SQL Server 2014)io
/*table
MicrosoftSQL Server 2014 - 12.0.2000.8 (X64)
Feb 20 2014 20:04:26
Copyright (c) Microsoft Corporation
Enterprise Edition (64-bit) on WindowsNT 6.3 <X64> (Build 9600: ) (Hypervisor)
*/
還原後在SQL 2014後查詢時提示出錯:
檢查方法:
在還原環境運行
SELECT OBJECT_NAME(object_id) AS TabName,name AS IndexName FROM sys.indexes WHERE is_disabled=1
解決方法:(生成重建索引語句)
1.生成語句
SELECT 'ALTER INDEX ' + a.name + ' ON ' + b.name + ' REBUILD;' FROM sys.indexes AS a INNER JOIN sys.tables AS b ON b.object_id = a.object_id WHERE a.name IS NOT NULL and a.is_disabled=1 ORDER BY 1
2.生成執行語句,在還原環境(SQL2014)對象的DB執行
發現有個共同點,在還原對象(表)中列都有用來空間類型geometry類型