Recently a friend of mine asked for a script, for documentation
purpose which can help them to create all of their indexes list with
column names used in each index. I thought, I must share this simple
script with my blog readers.
(Indexes list with usage statistics can be found here)
Your Personal ChatGPT Tutorial
1 day ago
Yeah, uh. This doesn't work.
ReplyDeleteSyntax error removed.. Now its working fine.
ReplyDeleteMade of win, this is a beautiful query to hook up to my index usage scripts, so I can immediately see which columns are involved in the unused/under-used indexes. Nice work!!
ReplyDeleteThis is really one of those great scripts! Thank you so much!
ReplyDeletebrilliant!
ReplyDeletethanks for the script
ReplyDeletethere is a problem with it, however - it is putting the "included" columns into the same list as index columns
to distinguish them is_included_column flag of
sys.[index_columns] table should be used
thanks, aedna.... Its corrected ;)
ReplyDeleteit helped me thanks
ReplyDeleteExcellent
ReplyDeleteThanks for posting this great script! It is a big help and nice work adding the suggestions of the commenters.
ReplyDeleteGreat script!! beautifuly done... thanks a lot.
ReplyDeleteNice script
ReplyDeleteGreat, that's what I was looking for, Thank you a lot!
ReplyDeleteGreat. It is very helpful. Thanks a lot.
ReplyDeleteGreat script - would be even better if you can make it display (select) the Schema as well, before TableName
ReplyDeleteThanks to point out. Script updated.
DeleteBig help!!! Marvelous, Best part of this query if list of include columns
ReplyDeleteThank you nice script specially to get include cols list.
ReplyDeleteThank you, just what I needed!
ReplyDeleteCool, thanks a lot,
ReplyDeleteI searched everywhere an tried to write my own script without success!
Great script!
Many thanks.
ReplyDeleteThis worked like magic. Learnt a lot from it.
I get a lot of NULL values. I had to add WHERE Ind.[name] is not null
ReplyDeleteExcellent work! very nice script.
ReplyDeleteExcellent!! Thanks
ReplyDeletethe link to the script doesn't work. Does anyone has a valid link to it?
ReplyDeletethanks!
You can directly download it from github https://gist.github.com/lionofdezert/3722342#file-alldbindexeslistwithincludecolumns-sql
DeleteWorks perfectly thx :)
ReplyDeletethx
ReplyDeleteyou saved my days.. thanks a lot for great work..really appreciate it!!
ReplyDeleteThanks, it helped me
ReplyDeletewhile executing this query I am getting error ORA-01747: invalid user.table.column, table.column, or column specification
ReplyDelete01747. 00000 - "invalid user.table.column, table.column, or column specification"
please help me on this
Sorry dear, but the above mention script works only for SQL Server.
DeleteThanks, Aasim, for sharing knowledge! Could you please help me for a script in which we may analyze performance of the indexes created on specified table(s)?
ReplyDeleteHere is a method to include data for XML indexes
ReplyDeleteSELECT DISTINCT * FROM (
SELECT
SI.name,
STUFF((
SELECT ';' + SC.name
FROM sys.index_columns SIC
INNER JOIN sys.columns SC
ON SC.object_id = SIC.object_id
AND SC.column_id = SIC.column_id
WHERE SI.object_id = SIC.object_id
AND SI.index_id = SIC.index_id
AND SIC.is_included_column = 0
ORDER BY SIC.index_column_id
FOR XML PATH ('')),1,1,'') AS KeyColumns
,STUFF((
SELECT ';' + SC.name
FROM sys.index_columns SIC
INNER JOIN sys.columns SC
ON SC.object_id = SIC.object_id
AND SC.column_id = SIC.column_id
WHERE SI.object_id = SIC.object_id
AND SI.index_id = SIC.index_id
AND SIC.is_included_column = 1
ORDER BY SIC.index_column_id
FOR XML PATH ('')),1,1,'') AS IncludeColumns
,SI.index_id
,SXI.xml_index_type_description
,SXI.secondary_type
,sxi.secondary_type_desc
,sxi.using_xml_index_id
FROM sys.indexes SI
INNER JOIN sys.sysobjects SO
ON SO.id = SI.object_id
INNER JOIN sys.schemas SS
ON SO.uid = SS.schema_id
INNER JOIN sys.index_columns SIC
ON SIC.object_id = SI.object_id
AND SIC.index_id= SI.index_id
INNER JOIN sys.columns SC
ON SC.object_id = SI.object_id
AND SC.column_id = SIC.column_id
LEFT OUTER JOIN sys.xml_indexes SXI
ON SI.object_id = SXI.object_id
AND SI.index_id = SXI.index_id
WHERE SO.name = 'Person'
AND SS.name = 'Person'
) AS X
ORDER BY X.index_id