Karena batasan unik diterapkan di bawah sampul sebagai indeks, Anda bisa mendapatkan semua informasi ini langsung dari sys.indexes:
SELECT
[schema] = OBJECT_SCHEMA_NAME([object_id]),
[table] = OBJECT_NAME([object_id]),
[index] = name,
is_unique_constraint,
is_unique,
is_primary_key
FROM sys.indexes
-- WHERE [object_id] = OBJECT_ID('dbo.tablename');
Untuk mengulang untuk semua database (dan mungkin tanpa filter untuk tabel tertentu):
DECLARE @sql NVARCHAR(MAX) = N'';
SELECT @sql += 'SELECT db = ' + name + ',
[schema] = OBJECT_SCHEMA_NAME([object_id]),
[table] = OBJECT_NAME([object_id]),
[index] = name,
is_unique_constraint,
is_unique,
is_primary_key
FROM ' + QUOTENAME(name) + '.sys.indexes;'
FROM sys.databases
WHERE database_id BETWEEN 4 AND 32766;
EXEC sp_executesql @sql;