SQL Server error 208
Invalid object name (SQL Server error 208)
SQL Server couldn’t find a table or view with that name from where your statement ran. Usually you’re in the wrong database, or the table is in another schema than your default (dbo); temp tables out of scope and case-sensitive databases give the same error.
Invalid object name 'accounts'.
Tested on SQL Server 2022 (16.0.4295.3); also 2019 (15.0.4490.9) and 2025 (17.0.5005.3) · Updated 9 October 2026
What it means
SQL Server looked for a table, view or other object with that name and didn’t find one. It resolves a name like this:
accounts: in the current database, in your default schema (usuallydbo), then indbo.sales.accounts: schemasales, in the current database.shop.sales.accounts: databaseshop, schemasales.#accounts: a temporary table that exists in your session right now.
Error 208 means none of those matched:
Msg 208, Level 16, State 1, Line 2
Invalid object name 'accounts'.
One thing makes 208 confusing: because of deferred name resolution, SQL Server lets you create a procedure that uses a table that doesn’t exist. The 208 comes later, when the procedure runs, with the procedure’s name and line in the message. (A table that exists but that you have no permission on gives error 229 instead.)
Common causes
- The wrong database. Your connection went to
master(or your login’s default database) because the connection string didn’t name one, or a script lacksUSE. - The table isn’t in your default schema. It’s
sales.accountsand you wroteaccounts, which SQL Server looks for asdbo.accounts. - A temp table out of scope. A
#temptable created inside dynamic SQL (EXEC('…')) or a stored procedure is dropped when that scope ends; the caller can’t see it. - Case, on a case-sensitive database:
dbo.orderswhen the table isdbo.Orders. - A misspelt name, or a database name in a three-part name that doesn’t exist.
- A procedure, view or synonym pointing at a table that was renamed or dropped, or never created on this server.
How to fix it
Check where you are
SELECT DB_NAME() AS current_database, SCHEMA_NAME() AS default_schema;
Name the database in the connection string (Database= or Initial Catalog=), or start scripts
with USE <database>;.
Find the table and its schema
SELECT s.name AS schema_name, o.name AS object_name, o.type_desc
FROM sys.objects AS o
JOIN sys.schemas AS s ON s.schema_id = o.schema_id
WHERE o.name LIKE '%account%'
ORDER BY s.name, o.name;
Then always write the schema: sales.accounts, not accounts. If a user should find tables in
another schema without a prefix, change their default schema:
ALTER USER [app] WITH DEFAULT_SCHEMA = sales;
If the table doesn’t show up in sys.objects but you know it exists, your user may have no
permission on it at all: catalog views only list objects you have some permission on. Querying it
then gives error 229, not 208.
Keep temp tables in scope
Create the #temp table in the outer scope, then fill it from the inner one: a temp table is visible
to procedures and dynamic SQL called after it was created, but not the other way round.
CREATE TABLE #recent (id int);
EXEC (N'INSERT INTO #recent (id) SELECT id FROM sales.orders WHERE created_at > DATEADD(day, -7, SYSDATETIME());');
SELECT id FROM #recent;
Match the case on case-sensitive databases
On a database whose collation contains _CS_ or _BIN, write object names exactly as they were
created. SELECT DATABASEPROPERTYEX(DB_NAME(), 'Collation') shows it.
Find what a procedure or view refers to
SELECT referenced_schema_name, referenced_entity_name, is_ambiguous
FROM sys.sql_expression_dependencies
WHERE referencing_id = OBJECT_ID('dbo.order_report');
A row with referenced_id NULL names something that didn’t exist when SQL Server last looked:
create it, or alter the procedure to use the new name.
Reproduce it
On SQL Server 2022 (RTM-CU27, 16.0.4295.3), database inlet, a login whose default schema is dbo,
and a table seo_sqlerr_conn.accounts:
SELECT DB_NAME() AS db, SCHEMA_NAME() AS default_schema; -- inlet, dbo
SELECT id FROM accounts;
Msg 208, Level 16, State 1, Server 7732422b7f56, Line 2
Invalid object name 'accounts'.
Connected to master instead, SELECT id FROM seo_sqlerr_conn.accounts; got
Invalid object name 'seo_sqlerr_conn.accounts'.. A temp table created in dynamic SQL:
EXEC ('CREATE TABLE #recent (id int); INSERT INTO #recent VALUES (1);');
SELECT id FROM #recent;
Msg 208, Level 16, State 1, Server 7732422b7f56, Line 2
Invalid object name '#recent'.
Created first in the outer batch, the same table worked. A procedure over a table that doesn’t
exist was created without complaint (sys.sql_expression_dependencies listed order_totals with
referenced_id NULL), and failed when run:
CREATE PROCEDURE seo_sqlerr_conn.order_report AS
SELECT id, total FROM seo_sqlerr_conn.order_totals;
GO
EXEC seo_sqlerr_conn.order_report;
Msg 208, Level 16, State 1, Server 7732422b7f56, Procedure seo_sqlerr_conn.order_report, Line 2
Invalid object name 'seo_sqlerr_conn.order_totals'.
A three-part name with a database that doesn’t exist, nosuchdb.dbo.accounts, and a misspelt
table, inlet.seo_sqlerr_conn.acounts, both got 208 with the full name. On a temporary SQL Server
2022 container, in a database created with Latin1_General_100_CS_AS, SELECT Id, Total FROM dbo.orders got Invalid object name 'dbo.orders'. when the table was dbo.Orders. SQL Server
2019 (15.0.4490.9) and 2025 (17.0.5005.3) gave the same errors.
In Inlet
Inlet’s sidebar lists the schemas of the database you’re connected to and the tables, views, sequences, functions and procedures in each, read from SQL Server’s system views, so you can see which schema a table is really in. Query tabs run T-SQL a batch at a time, and temp tables work there as they do in any session. When a statement fails with 208, the error links to this page.
Related
Sources
- learn.microsoft.com/en-us/sql/relational-databases/stored-procedures/create-a-stored-procedure
- learn.microsoft.com/en-us/sql/t-sql/statements/create-procedure-transact-sql
- learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql#temporary-tables
- learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/ownership-and-user-schema-separation
- learn.microsoft.com/en-us/sql/relational-databases/security/metadata-visibility-configuration
- learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-sql-expression-dependencies-transact-sql