Last afternoon I was in the middle of trying to respond to one of my counter parts describing why one the developers I worked with had written a procedure in particular manner. I knew I had placed two columns in the include list but sp_helpindex never should the columns in the view. The only way I know of verifying if a index has a include list is by going through object exploreà…. àtable à index.
For me this thought was way too painful and this simple script is a result of that
I haven’t taken the trouble to concatenate the columns
declare @TableName varchar(100)
SET @TableName = 'Production.ProductReview' – include the the table name along with the schema name
SELECT object_id(@TableName) TableName ,SI.Name , SI.type_desc , SI.is_primary_key
,SC.name ColumneName
,SIC.column_id
,SIC.is_included_column -- this column will signify if a filed is a part of the include list
FROM sys.indexes SI
JOIN sys.index_columns SIC ON SI.object_id = SIC.object_id AND SI.index_id = SIC.index_id
JOIN Sys.columns SC ON SC.object_id = SIC.object_id AND SC.column_id = SIC.column_id
WHERE SI.object_id= object_id(@TableName)
Enjoy
I haven’t taken the trouble to concatenate the columns
declare @TableName varchar(100)
SET @TableName = 'Production.ProductReview' – include the the table name along with the schema name
SELECT object_id(@TableName) TableName ,SI.Name , SI.type_desc , SI.is_primary_key
,SC.name ColumneName
,SIC.column_id
,SIC.is_included_column -- this column will signify if a filed is a part of the include list
FROM sys.indexes SI
JOIN sys.index_columns SIC ON SI.object_id = SIC.object_id AND SI.index_id = SIC.index_id
JOIN Sys.columns SC ON SC.object_id = SIC.object_id AND SC.column_id = SIC.column_id
WHERE SI.object_id= object_id(@TableName)
Enjoy
Comments
Post a Comment