Eftersom unika begränsningar är implementerade under omslagen som index, kan du få all denna information direkt från 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');
För att upprepa för alla databaser (och förmodligen utan filtret för en specifik tabell):
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;