I am looking for T-SQL code to list all tables in all databases in SQL Server (at least in SS2005 and SS2008; would be nice to also apply to SS2000). The catch, however, is
I quite like using INFORMATION_SCHEMA for this as I get the DB name for free. That and - realising from @KM post that multiple results sets insert nicely - I came up with:
select top 0 *
into #temp
from INFORMATION_SCHEMA.TABLES
insert into #temp
exec sp_msforeachdb 'select * from [?].INFORMATION_SCHEMA.TABLES'
select * from #temp
drop table #temp