Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Could not locate entry in sysdatabases for database Expand / Collapse
Author
Message
Posted Wednesday, December 15, 2010 8:36 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 3:52 PM
Points: 377, Visits: 685
I am trying to run the following and I get the error "Could not locate entry in sysdatabases for database".
sp_msforeachdb 'USE ?;select distinct db_name()'

I know that one of the db name is longer.

Any ideas?

Thanks.
Post #1035205
Posted Wednesday, December 15, 2010 8:44 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 10:19 AM
Points: 43,026, Visits: 36,192
Does it change anything if you wrap the dbname in [] in the use statement?

sp_msforeachdb 'USE [?];select db_name()'

p.s. No need for distinct, you're selecting a single constant value.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1035222
Posted Wednesday, December 15, 2010 8:48 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 3:52 PM
Points: 377, Visits: 685
Adding brackets around "[?]" was a common sense and I am missing it. Thank you very much.
Post #1035225
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse