I blog about debugging, development using .net, C#, SQL, and other Microsoft technologies.
Disclaimer: All posts are provided "AS IS" with no warranties, confering no rights, and expressing only my personal opinion, not Microsoft's.
exec sp_MsForEachDB 'SELECT "?", 1'
The ? will be replaced by the current database name. To run a query that references a table, you need to make sure that the table exists first, as this query will run on system databases as well.