0

Up until today I've been able to run queries without using the [databaseName].[dbo].[fieldName] syntax. And all of a sudden, if I use select * from myTable I get an error for an invalid object. I can't possibly think of something that happened between shutting down my PC yesterday and today. Anyone know anything about this?

Msg 208, Level, 16, State 1 Line 1
Invalid object name 'mytable'

It's only been since today that I have to include the database name in the query. There are no other connections open and no other users of this instance of SQL Server.

2
  • 1
    post the actual query and actual error you are getting, so that we can help you. Commented Mar 28, 2012 at 13:10
  • 1
    you are using the databaseName,right? Commented Mar 28, 2012 at 13:23

1 Answer 1

5

I think you mean a query of the form select [fieldName] from [databaseName].[dbo].[mytable]

Here are some possible things to look out for:

  • Make sure that you are in the correct database context / catalogue (i.e. use [databasename], or select the correct database from the Available Databases drop down in SSMS)

enter image description here

  • Ensure that if you have a case sensitive collation on your database that the object names in your query match the exact case.
  • Check that the default schema for your user hasn't changed on this database. Although the default schema is usually [dbo], it can be changed.

Edit : More ideas:

  • Do SELECT DB_NAME() to see what the current database name is.
  • Check to see if someone has dropped the table or view entirely, e.g. from the target database, run:

Select * from sysobjects where name = 'myobject' 
OR
Select * from sys.tables where name = 'mytable' 
OR
Select * from INFORMATION_SCHEMA.TABLES
Sign up to request clarification or add additional context in comments.

2 Comments

the schema hasn't changed, and case sensitivity hasn't changed. I'm not sure what exactly you mean with the database context/catalogue.
I have a crappy touch pad on my laptop and I was using the wrong database. To the direct left of the execute button for running queries, where it has a list of the databases on your SQL Server, what's that thing called? That's where my problem was. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.