Как и любая таблица, вы можете быстро получить детали индекса с помощью sp_help
:
EXEC sp_help N'dbo.Users';
Подробности индекса будут такими:
+-----------------------------+------------------------------------------------------+---------------------------+
| index_name | index_description | index_keys |
+-----------------------------+------------------------------------------------------+---------------------------+
| PK__Users__5A5B77D52FBBA93E | nonclustered, unique, primary key located on PRIMARY | path_locator |
| UQ__Users__9DD95BAF3C1BB377 | nonclustered, unique, unique key located on PRIMARY | stream_id |
| UQ__Users__A236CBB35BE6FD63 | nonclustered, unique, unique key located on PRIMARY | parent_path_locator, name |
+-----------------------------+------------------------------------------------------+---------------------------+
Приведенный ниже запрос вернет имя ограничения и имена столбцов с использованием представлений каталога:
SELECT kc.name AS constraint_name, c.name AS column_name
FROM sys.filetables AS t
JOIN sys.key_constraints AS kc ON kc.parent_object_id = t.object_id
JOIN sys.index_columns AS ic ON ic.object_id = kc.parent_object_id AND ic.index_id = kc.unique_index_id
JOIN sys.columns AS c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
WHERE t.object_id = OBJECT_ID(N'dbo.Users', 'U')
ORDER BY kc.name, ic.key_ordinal;