Declare @Qry_Results nvarchar(max)
select @Qry_Results = coalesce(@Qry_Results + char(13) + char(10) + ' UNION ALL ','') +
'
SELECT ' + QUOTENAME([Name],'''') + ' as DBName, [AGGREGATE_FUNCTION], [CHECK_CONSTRAINT],[DEFAULT_CONSTRAINT],[FOREIGN_KEY_CONSTRAINT],
[SQL_SCALAR_FUNCTION],[CLR_SCALAR_FUNCTION],[CLR_TABLE_VALUED_FUNCTION],[SQL_INLINE_TABLE_VALUED_FUNCTION],[INTERNAL_TABLE],
[SQL_STORED_PROCEDURE],[CLR_STORED_PROCEDURE],[PLAN_GUIDE],[PRIMARY_KEY_CONSTRAINT],[RULE],[REPLICATION_FILTER_PROCEDURE],
[SYNONYM],[SERVICE_QUEUE],[CLR_TRIGGER],[SQL_TABLE_VALUED_FUNCTION],[SQL_TRIGGER],[TABLE_TYPE],[USER_TABLE],[UNIQUE_CONSTRAINT],
[VIEW],[EXTENDED_STORED_PROCEDURE]
from
(
select [Name], type_Desc
from ' + quotename([Name]) + '.sys.objects where is_ms_shipped = 0) src
PIVOT (
count([Name])
FOR type_desc in ([AGGREGATE_FUNCTION], [CHECK_CONSTRAINT],[DEFAULT_CONSTRAINT],[FOREIGN_KEY_CONSTRAINT],[SQL_SCALAR_FUNCTION],
[CLR_SCALAR_FUNCTION],[CLR_TABLE_VALUED_FUNCTION],[SQL_INLINE_TABLE_VALUED_FUNCTION],[INTERNAL_TABLE],[SQL_STORED_PROCEDURE],
[CLR_STORED_PROCEDURE],[PLAN_GUIDE],[PRIMARY_KEY_CONSTRAINT],[RULE],[REPLICATION_FILTER_PROCEDURE],[SYNONYM],[SERVICE_QUEUE],
[CLR_TRIGGER],[SQL_TABLE_VALUED_FUNCTION],[SQL_TRIGGER],[TABLE_TYPE],[USER_TABLE],[UNIQUE_CONSTRAINT],[VIEW],[EXTENDED_STORED_PROCEDURE]
)
) pvt
'
from sys.databases
where [name] NOT IN ('master','tempdb','model','msdb') order by [Name]
execute(@Qry_Results)
No comments:
Post a Comment