Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

sp_MSforeachdb don't see my DBs

$
0
0

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:

master
Msg 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


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>