May 17, 2026, 11:40 PM

This commit is contained in:
Paweł Domański
2026-05-18 06:40:19 +00:00
commit 64944cf004
896 changed files with 310709 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
---------------------------------------------------------------------------------------------------------------------------
-- Purpose: This query will list all indexes in the database and show index columns and included columns using STRING_AGG (SQL 2017 and later). Run this in the user database.
-- More Information:
-- Revision: 2019-05-21
--
SELECT
SCHEMA_NAME(ss.SCHEMA_id) AS SCHEMANAME,
ss.name as TableName,
ss2.name as IndexName,
ss2.index_id,
(SELECT STRING_AGG(name,', ')
FROM sys.index_columns a INNER JOIN sys.all_columns b ON a.object_id = b.object_id and a.column_id = b.column_id and a.object_id = ss.object_id and a.index_id = ss2.index_id and is_included_column = 0
) as IndexColumns,
(SELECT STRING_AGG(name,', ')
FROM sys.index_columns a INNER JOIN sys.all_columns b ON a.object_id = b.object_id and a.column_id = b.column_id and a.object_id = ss.object_id and a.index_id = ss2.index_id and is_included_column = 1
) as IncludedColumns
FROM sys.objects SS INNER JOIN sys.indexes ss2 ON ss.OBJECT_ID = ss2.OBJECT_ID
WHERE ss.type = 'U'
ORDER BY 1, 2, 3