if object_ID('TempDB..#AllTables' ,'U') IS NOT NULL drop table #AllTables
CREATE TABLE #AllTables (
[DB Name] sysname,
[Views] int)
DECLARE @SQL NVARCHAR(MAX)
SELECT @SQL = COALESCE(@SQL,'') + 'USE ' + quotename(name) + '
insert into #AllTables
select ' + QUOTENAME(name,'''') + ' as [DB Name],
(select count(*) from ' + QUOTENAME(Name) + '.sys.views)
'
FROM sys.databases
where state_desc = 'ONLINE'
ORDER BY name
-- print @SQL -- debug
EXECUTE(@SQL)
SELECT * FROM #AllTables order by Views desc