// SQL Server error reference

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
Error message
Invalid object name '%.*ls'.

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

  1. 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%';
  2. 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;
  3. 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;
  4. For temp tables, remember that a #temp table 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

More names and objects errors

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.

// fewer errors, faster fixes

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.