SQL Server error 208: Invalid object name
SQL Server can't find the table, view or other object the query names: wrong database, missing schema, a typo, or an object that doesn't exist yet.
- Error number
208- Severity
- 16
- Category
- Names and objects
What it means
When a statement is compiled, SQL Server resolves every table and view name. A one-part name like Orders is looked up in your default schema and then in dbo of the current database. If nothing matches, the batch fails with 208 and names the object it couldn't find.
One exception is worth knowing: inside a stored procedure, a missing table is allowed at create time (deferred name resolution) and only fails with 208 when the procedure runs.
Common causes
- The query runs in the wrong database, often
master, because the connection's default database isn't the one you meant. - The object is in another schema than your default and the name isn't schema-qualified.
- A typo, or a case difference on a database with a case-sensitive collation.
- The object was dropped, renamed, or not created yet, for example a temp table created in a different scope or session.
- A synonym that points to an object that no longer exists.
How to fix it
-
Check where you are and whether the object exists there.
SELECT DB_NAME() AS current_db, SCHEMA_NAME() AS default_schema; SELECT s.name AS schema_name, o.name, o.type_desc FROM sys.objects o JOIN sys.schemas s ON s.schema_id = o.schema_id WHERE o.name LIKE N'%Order%';
-
Switch to the right database, or qualify the name fully.
USE SalesDb; SELECT TOP (10) * FROM Sales.Orders; -- or: SELECT TOP (10) * FROM SalesDb.Sales.Orders;
-
If the object lives in another database or server, use a three- or four-part name, or create a synonym.
CREATE SYNONYM dbo.Orders FOR SalesDb.Sales.Orders;
-
For temp tables, remember that a
#temptable created inside a procedure or dynamic SQL disappears when that scope ends.
Reproduce it safely
SELECT * FROM dbo.TableThatDoesNotExist; -- Msg 208: Invalid object name 'dbo.TableThatDoesNotExist'.
Questions
Why does the query work in SSMS but fail with 208 in my application?
The two connections usually start in different databases or run as different users with different default schemas. Schema-qualify the name and set the database in the connection string.
Related errors
207Invalid column name2812Could not find stored procedure4104Multi-part identifier not bound42P01PostgreSQL: relation does not exist1146MySQL: Table doesn't existORA-00942Oracle: table or view does not exist
More names and objects errors
209Ambiguous column name2714There is already an object named3701Cannot drop, object not found3702Cannot drop database, currently in use5030Database couldn't be exclusively locked8144Too many arguments specified8145Is not a parameter for procedure8146Procedure has no parameters
The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.
Work on SQL Server in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.