以下測(cè)試?yán)右許QL 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后查詢時(shí)提示出錯(cuò):
檢查方法:
在還原環(huán)境運(yùn)行
SELECT OBJECT_NAME(object_id) AS TabName,name AS IndexName FROM sys.indexes WHERE is_disabled=1
解決方法:(生成重建索引語(yǔ)句)
1.生成語(yǔ)句
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í)行語(yǔ)句,在還原環(huán)境(SQL2014)對(duì)象的DB執(zhí)行
發(fā)現(xiàn)有個(gè)共同點(diǎn),在還原對(duì)象(表)中列都有用來(lái)空間類型geometry類型