|
sql
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem in sysdatabases
I get the following error message when I try and loop through all databases
to perform a query using sp_MSforeachdb. 'Could not locate entry in sysdatabases for database 'OrtusSearch'. No entry found with that name. Make sure that the name is entered correctly.' However where I run the below code I get no results. select * from sysdatabases where name = 'ortussearch' I have an entry in sysdatabases for an ortussearch.com database. I don`t understand why I am getting the above situation. Any thoughts ? Seems like sp_MSforeachdb doesn't handle databases with names that
doesn't confirm to standard identifiers. This is always the risk you take when using non-supported features (like sp_MSforeachdb). I suggest you use the source for for this proc as base for your own version which does handle non-standard identifiers as database names. Of course, if the database didn't have that stupid name in the first place, you wouldn't have this problem (best practice is to follow rules for standard identifiers). -- Show quoteHide quoteTibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://sqlblog.com/blogs/tibor_karaszi "Simon" <Si***@discussions.microsoft.com> wrote in message news:4AF256DA-4C2A-4095-9520-DA4E917F59A8@microsoft.com... >I get the following error message when I try and loop through all >databases > to perform a query using sp_MSforeachdb. > > 'Could not locate entry in sysdatabases for database 'OrtusSearch'. > No entry > found with that name. Make sure that the name is entered correctly.' > > However where I run the below code I get no results. > > select * from sysdatabases > where name = 'ortussearch' > > I have an entry in sysdatabases for an ortussearch.com database. I > don`t > understand why I am getting the above situation. Any thoughts ? At least in most cases, you can use sp_MSforeachdb with non-standard names.
You just have to make sure that the queries you are having sp_MSforeachdb build are correct. sp_MSforeachdb just blindly replaces each occurance of ? with the name of the database. So if you do, Create Database [very bad database name] Then sp_MSforeachdb 'Print ''?''' will work just fine. But sp_MSforeachdb 'Select ''?'', count(*) From ?.dbo.sysobjects' will give you an error because it will try to execute Select 'very bad database name', count(*) From very bad database name.dbo.sysobjects which is, of course, not legal. However, you can do sp_MSforeachdb 'Select ''?'', count(*) From [?].dbo.sysobjects' because that executes Select 'very bad database name', count(*) From [very bad database name].dbo.sysobjects which is legal. If you run the above tests, don't forget to Drop Database [very bad database name] when you are done, and I agree 1000% with Tibor that you should always use standard names. Tom Show quoteHide quote "Tibor Karaszi" <tibor_please.no.email_kara***@hotmail.nomail.com> wrote in message news:Onww%236iVJHA.5032@TK2MSFTNGP05.phx.gbl... > Seems like sp_MSforeachdb doesn't handle databases with names that doesn't > confirm to standard identifiers. This is always the risk you take when > using non-supported features (like sp_MSforeachdb). I suggest you use the > source for for this proc as base for your own version which does handle > non-standard identifiers as database names. Of course, if the database > didn't have that stupid name in the first place, you wouldn't have this > problem (best practice is to follow rules for standard identifiers). > > -- > Tibor Karaszi, SQL Server MVP > http://www.karaszi.com/sqlserver/default.asp > http://sqlblog.com/blogs/tibor_karaszi > > > "Simon" <Si***@discussions.microsoft.com> wrote in message > news:4AF256DA-4C2A-4095-9520-DA4E917F59A8@microsoft.com... >>I get the following error message when I try and loop through all >>databases >> to perform a query using sp_MSforeachdb. >> >> 'Could not locate entry in sysdatabases for database 'OrtusSearch'. No >> entry >> found with that name. Make sure that the name is entered correctly.' >> >> However where I run the below code I get no results. >> >> select * from sysdatabases >> where name = 'ortussearch' >> >> I have an entry in sysdatabases for an ortussearch.com database. I don`t >> understand why I am getting the above situation. Any thoughts ? > Good catch, Tom!
-- Show quoteHide quoteTibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://sqlblog.com/blogs/tibor_karaszi "Tom Cooper" <tomcooper@comcast.no.spam.please.net> wrote in message news:%23tGzSpnVJHA.1184@TK2MSFTNGP05.phx.gbl... > At least in most cases, you can use sp_MSforeachdb with non-standard > names. You just have to make sure that the queries you are having > sp_MSforeachdb build are correct. sp_MSforeachdb just blindly > replaces each occurance of ? with the name of the database. So if > you do, > > Create Database [very bad database name] > > Then > sp_MSforeachdb 'Print ''?''' > will work just fine. > > But > sp_MSforeachdb 'Select ''?'', count(*) From ?.dbo.sysobjects' > will give you an error because it will try to execute > Select 'very bad database name', count(*) From very bad database > name.dbo.sysobjects > which is, of course, not legal. > > However, you can do > sp_MSforeachdb 'Select ''?'', count(*) From [?].dbo.sysobjects' > because that executes > Select 'very bad database name', count(*) From [very bad database > name].dbo.sysobjects > which is legal. > > If you run the above tests, don't forget to > Drop Database [very bad database name] > when you are done, and I agree 1000% with Tibor that you should > always use standard names. > > Tom > > "Tibor Karaszi" <tibor_please.no.email_kara***@hotmail.nomail.com> > wrote in message news:Onww%236iVJHA.5032@TK2MSFTNGP05.phx.gbl... >> Seems like sp_MSforeachdb doesn't handle databases with names that >> doesn't confirm to standard identifiers. This is always the risk >> you take when using non-supported features (like sp_MSforeachdb). I >> suggest you use the source for for this proc as base for your own >> version which does handle non-standard identifiers as database >> names. Of course, if the database didn't have that stupid name in >> the first place, you wouldn't have this problem (best practice is >> to follow rules for standard identifiers). >> >> -- >> Tibor Karaszi, SQL Server MVP >> http://www.karaszi.com/sqlserver/default.asp >> http://sqlblog.com/blogs/tibor_karaszi >> >> >> "Simon" <Si***@discussions.microsoft.com> wrote in message >> news:4AF256DA-4C2A-4095-9520-DA4E917F59A8@microsoft.com... >>>I get the following error message when I try and loop through all >>>databases >>> to perform a query using sp_MSforeachdb. >>> >>> 'Could not locate entry in sysdatabases for database >>> 'OrtusSearch'. No entry >>> found with that name. Make sure that the name is entered >>> correctly.' >>> >>> However where I run the below code I get no results. >>> >>> select * from sysdatabases >>> where name = 'ortussearch' >>> >>> I have an entry in sysdatabases for an ortussearch.com database. I >>> don`t >>> understand why I am getting the above situation. Any thoughts ? >> > >
Other interesting topics
Cursor Help
Error logs enormous. Can I delete or save elsewhere? MS Access, ODBC, SQL 2005, delays before data appears Script to delete records from a table older than N number of days. how to store decimals in tables Security Question Can a trigger be inadvertantly disabled? SQL SErver 64 bit use of memory The time stamp counter of CPU on scheduler id X is not synchronized with other CPUs DBCC Checkdb's torn page / checksum validation |
|||||||||||||||||||||||