Q&A for those who study, teach, research and apply economics and econometrics
select dbid, name into #dbs from master..sysdatabases where name not in ('Data.StackExchange', 'master', 'model', 'msdb', 'tempdb') declare @id int, @db varchar(40), @sql varchar(100) while (select count(*) from #dbs) > 0 begin select top 1 @id = dbid, @db = name from #dbs set @sql = 'print ''' + @db + '''' exec (@sql) delete from #dbs where dbid = @id end