腳本過濾索引爲我工作得很好。下面是一些測試代碼,你可以嘗試:
創建一個使用Adventworks篩選的索引(從BOL爲例):
USE AdventureWorks2008R2;
GO
IF EXISTS (SELECT name FROM sys.indexes
WHERE name = N'FIBillOfMaterialsWithEndDate'
AND object_id = OBJECT_ID(N'Production.BillOfMaterials'))
DROP INDEX FIBillOfMaterialsWithEndDate
ON Production.BillOfMaterials;
GO
CREATE NONCLUSTERED INDEX "FIBillOfMaterialsWithEndDate"
ON Production.BillOfMaterials (ComponentID, StartDate)
WHERE EndDate IS NOT NULL;
GO
使用SQLPS導航到Production.BillOfMaterials表的索引容器:
cd SQLSERVER:\SQL\WIN7BOOT\SQL1\Databases\AdventureWorks\Tables\Production.BillOfMaterials\indexes
獲取FIBillOfMaterialsWithEndDate指數和腳本是:
get-item FIBillOfMaterialsWithEndDate | foreach {$_.script()};
CREATE NONCLUSTERED INDEX [FIBillOfMaterialsWithEndDate] ON [Production].[BillOfMaterials]
(
[ComponentID] ASC,
[StartDate] ASC
)
WHERE ([EndDate] IS NOT NULL)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF,
ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]