There's an undocumented Stored Procedure that can help:
Procedure:
sp_MSforeachdb
@command1
@replacechar = '?'
[,@command2]
[,command3]
[,@whereand]
[,@precommand]
[,@postcommand]
Purpose:
execute up to three commands for every database on the system. @replacechar will be replaced with the name of each database. @precommand and @postcommand can be used to direct commands to a single result set.
Example:
EXEC sp_MSforeachdb @command1 = 'Print "Listing ?=', @command2 = 'SELECT * FORM ?', @whereand = ' AND name like "title%"'
-From the Gurus's Guide to Transact-SQL by Ken Henderson
-SQLBill