以下測試例子以SQL 2008備份,在SQL2014還原,造成索引被禁用.
--備份環(huán)境(SQL Server 2008 R2)
/*
MicrosoftSQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
Apr 2 2010 15:48:46
Copyright (c) Microsoft Corporation
Data Center Edition (64-bit) on WindowsNT 6.1
*/
--還原環(huán)境(SQL Server 2014)
/*
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
*/
還原后在SQL 2014后查詢時提示出錯:
檢查方法:
在還原環(huán)境運行
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_idWHERE a.name IS NOT NULLORDER BY 1
2.生成執(zhí)行語句,在還原環(huán)境(SQL2014)對象的DB執(zhí)行
發(fā)現(xiàn)有個共同點,在還原對象(表)中列都有用來空間類型geometry類型