- Improve query performance. Statistics are more accurate which can result in better query plans.
- Reduce index maintenance costs. An index is only maintained when the data in the index is changed.
- Reduce index storage costs.
- Columns which contains mostly NULL values and where queries retrieve only the rows where the data is NOT NULL.
- When you want to enforce uniqueness for a set of values. With a filtered index you can create a unique index for the set of values. For instance
CREATE UNIQUE NONCLUSTERED INDEX CustomerID_NOTNULL ON Accounts (CustomerID) WHERE CustomerID IS NOT NULL - When analyzing data on a specific data range. For instance you have a table with records for the last 4 years (2006,2007,2008,2009). You are analyzing only the year 2009. A filtered index will look like
CREATE INDEX YEAR2009 ON Transactions (Year,Period, Amount) WHERE Year = 2009
- CREATE INDEX YEAR ON Transactions (Year,Period, Amount)
- CREATE INDEX YEAR2009 ON Transactions (Year,Period, Amount) WHERE Year = 2009
DECLARE @TableName VARCHAR(100)
SET @TableName = 'fill in the tablename'
SELECT db.index_id,si.name, IndexSizeKB = SUM(page_count * 8)
FROM sys.dm_db_index_physical_stats(db_id(),object_id(@TableName),NULL,NULL,'DETAILED') db
INNER JOIN sys.indexes SI ON SI.index_id = db.index_id AND SI.object_id = object_id(@TableName)
GROUP BY db.index_id ,si.name
ORDER BY db.index_id desc,si.name
No comments:
Post a Comment