Skip to content

Instantly share code, notes, and snippets.

@xivSolutions
Created September 21, 2016 19:47
Show Gist options
  • Save xivSolutions/67da7f1d8828e2d4319147b2f4f8dab8 to your computer and use it in GitHub Desktop.
Save xivSolutions/67da7f1d8828e2d4319147b2f4f8dab8 to your computer and use it in GitHub Desktop.
SQL Server Find Indexes
select
i.name as IndexName,
o.name as TableName,
ic.key_ordinal as ColumnOrder,
ic.is_included_column as IsIncluded,
co.[name] as ColumnName
from sys.indexes i
join sys.objects o on i.object_id = o.object_id
join sys.index_columns ic on ic.object_id = i.object_id
and ic.index_id = i.index_id
join sys.columns co on co.object_id = i.object_id
and co.column_id = ic.column_id
where i.[type] = 2
and i.is_unique = 0
and i.is_primary_key = 0
and o.[type] = 'U'
--and ic.is_included_column = 0
order by o.[name], i.[name], ic.is_included_column, ic.key_ordinal
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment