Hello, all!
I made the next query:
EXEC sp_MSforeachdb 'IF ''?'' <> ''master'' AND ''?'' <> ''model'' AND ''?'' <> ''tempdb'' AND ''?'' <> ''msdb'' BEGIN PRINT ''?'' SELECT ''?'', MyData FROM ?..MyTable END'
On my local SQL Server all works fine, but when I try to run this query on another SQL Server (the same version and edition like my SQL Server) - sp_MSforeachdb doesn't see any DBs but also query returned no errors: Command(s) completed successfully.
When I tried to exclude
IF ''?'' <> ''master'' AND ''?'' <> ''model'' AND ''?'' <> ''tempdb'' AND ''?'' <> ''msdb''
- the query returned erorrs:
masterMsg 208, Level 16, State 1, Line 2
Invalid object name 'master..MyTable'.
tempdb
Msg 208, Level 16, State 1, Line 2
Invalid object name 'tempdb..MyTable'.
model
Msg 208, Level 16, State 1, Line 2
Invalid object name 'model..MyTable'.
msdb
Msg 208, Level 16, State 1, Line 2
Invalid object name 'msdb..MyTable'.
So it means than sp_MSforeachdb can see the system DBs but don't see another DBs.
Why is it happen and how to decide this problem ?
Andy Mishechkin