{"id":108057,"date":"2025-12-18T15:27:51","date_gmt":"2025-12-18T15:27:51","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=108057"},"modified":"2026-02-19T19:32:21","modified_gmt":"2026-02-19T19:32:21","slug":"common-sql-server-problems-invalid-object-name","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/common-sql-server-problems-invalid-object-name\/","title":{"rendered":"How to fix the Invalid Object Name error in SQL Server"},"content":{"rendered":"\n<p>This post is part of a <a href=\"https:\/\/www.red-gate.com\/simple-talk\/collections\/common-issues-in-sql-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">series on common issues encountered in SQL Server<\/a>. This time, we\u2019ll talk about the invalid object name error:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:tsql decode:true \">Msg 208, Level 16, State 1\n\nInvalid object name '{object_name}'.<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-causes-of-the-invalid-object-name-error-in-sql-server-and-how-to-prevent-it\">Causes of the Invalid Object Name error in SQL Server &#8211; and how to prevent it<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-typo\">Typo<\/h4>\n\n\n\n<p>The object really could just be spelled wrong \u2013 I couldn\u2019t tell you how many times I had an obvious typo staring me in the face, and was convinced <a href=\"https:\/\/www.microsoft.com\/en-gb\/sql-server\/sql-server-downloads\" target=\"_blank\" rel=\"noreferrer noopener\">SQL Server<\/a> was wrong. Always use copy &amp; paste or, better yet, rely on <a href=\"https:\/\/code.visualstudio.com\/docs\/editing\/intellisense\" target=\"_blank\" rel=\"noreferrer noopener\">IntelliSense<\/a>\/auto-complete \u2013 that\u2019s why they\u2019re there. <\/p>\n\n\n\n<p><em>Additionally, products like Redgate&#8217;s SQL Prompt feature <a href=\"https:\/\/www.red-gate.com\/products\/sql-prompt\/#writing-code\" target=\"_blank\" rel=\"noreferrer noopener\">Intelli-Sense-style auto-complete<\/a> built in to the tool.<\/em><\/p>\n\n\n\n<p>You could also be using a case or binary-sensitive database or instance. In a case-sensitive database, for example, the following will yield the invalid object name error:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:tsql decode:true \">CREATE TABLE dbo.Users(UserId int);\n\nSELECT UserId FROM dbo.users;<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-the-object-doesn-t-exist-yet\">The object doesn&#8217;t exist yet<\/h4>\n\n\n\n<p>Sometimes this error just stems from creating objects in the wrong dependency order. SQL Server allows you to take advantage of <a href=\"https:\/\/learn.microsoft.com\/en-us\/previous-versions\/sql\/sql-server-2005\/ms190686(v=sql.90)\" target=\"_blank\" rel=\"noreferrer noopener\">deferred name resolution<\/a> with stored procedures; for example:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:tsql decode:true \">CREATE PROCEDURE dbo.ExampleProcedure\n\nAS\n\nSELECT ColumnName FROM dbo.does_not_exist_yet;<\/pre><\/div>\n\n\n\n<p>SQL Server lets you create the procedure with an <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/t-sql-programming-sql-server\/dependencies-and-references-in-sql-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">invalid reference<\/a>, trusting that you\u2019ll get around to creating the object prior to execution. This will also work with <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/t-sql-programming-sql-server\/sql-server-functions-the-basics\/#:~:text=or%20Table%2Dvalued-,Scalar%20functions,-return%20a%20single\" target=\"_blank\" rel=\"noreferrer noopener\">scalar functions<\/a>. You can\u2019t do the same with <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/mastering-sql-views\/\" target=\"_blank\" rel=\"noreferrer noopener\">views<\/a> (or table-valued functions):<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:tsql decode:true \">CREATE VIEW dbo.ExampleView\n\nAS\n\nSELECT ColumnName FROM dbo.does_not_exist_yet;<\/pre><\/div>\n\n\n\n<p>Trying to create this view yields the invalid object name error.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-wrong-object-type\">Wrong object type<\/h4>\n\n\n\n<p>You may have created a scalar function but are trying to call it like an inline <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/t-sql-programming-sql-server\/sql-server-functions-the-basics\/#table-valued-functions:~:text=Employees%22.-,Table%2Dvalued%20Functions,-Table%2Dvalued%20Functions\" target=\"_blank\" rel=\"noreferrer noopener\">table-valued function<\/a>, or a multi-statement table-valued function if you\u2019re into those for some reason (but generally they should be avoided). The following code returns the invalid object name error message, but I think a more dedicated error would be better:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:tsql decode:true \">CREATE FUNCTION dbo.ExampleScalar() \nRETURNS int\nAS \nBEGIN \n  RETURN (SELECT i = 1); \nEND \nGO \n\nSELECT * FROM dbo.ExampleScalar();<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-wrong-version-environment\">Wrong version\/environment<\/h4>\n\n\n\n<p>You may have grabbed sample code from somewhere and tried to use it in an older version, where that object simply didn\u2019t exist yet. For example, one of the <a href=\"https:\/\/www.brentozar.com\/archive\/2025\/05\/new-objects-in-sql-server-2025\/\" target=\"_blank\" rel=\"noreferrer noopener\">new internal tables in SQL Server 2025<\/a> is called <code>sys.pause_resume_history<\/code>. If you try to query this table in <a href=\"https:\/\/www.microsoft.com\/en-gb\/sql-server\/sql-server-2022\" target=\"_blank\" rel=\"noreferrer noopener\">SQL Server 2022<\/a> or lower, you will get the invalid object name error.<\/p>\n\n\n\n<p>Or you may have expected \u2013 maybe even really, really wanted \u2013 an object available in <a href=\"https:\/\/azure.microsoft.com\/en-us\/products\/azure-sql\/database\" target=\"_blank\" rel=\"noreferrer noopener\">Azure SQL Database<\/a> or <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/azure-sql\/managed-instance\/sql-managed-instance-paas-overview?view=azuresql\" target=\"_blank\" rel=\"noreferrer noopener\">Azure SQL Managed Instance<\/a> to also be present on-premises. Some examples of this are <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/system-dynamic-management-views\/sys-dm-db-resource-stats-azure-sql-database?view=azuresqldb-current\" target=\"_blank\" rel=\"noreferrer noopener\"><code>sys.dm_db_resource_stats<\/code><\/a> and <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/system-catalog-views\/sys-server-resource-stats-azure-sql-database?view=azuresqldb-current\" target=\"_blank\" rel=\"noreferrer noopener\"><code>sys.server_resource_stats<\/code><\/a>. If you try to access these views in any on-premises version of SQL Server \u2013 even SQL Server 2025 \u2013 you will get invalid object name.<\/p>\n\n\n\n<p>The reverse can also be true \u2013 trying to reference a system object in a cloud platform that only exists in on-premises versions.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Wrong scope<\/h4>\n\n\n\n<p>It is possible you created a <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/t-sql-programming-sql-server\/temporary-tables-in-sql-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">#temp table<\/a> but it\u2019s no longer in scope, because:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>It was created in dynamic SQL, for example:<\/li>\n<\/ul>\n<\/div>\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:tsql decode:true \">EXEC sys.sp_executesql N'CREATE TABLE #a(i int);'; \nSELECT * FROM #a;<\/pre><\/div>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>Your session was disconnected.<br><br><\/li>\n\n\n\n<li>The server restarted\/failed over.<\/li>\n<\/ul>\n<\/div>\n\n\n<p>Similar things can happen when a global ##temp table falls out of scope for any of the above reasons, or just because the last active session touching it ended. <\/p>\n\n\n\n<p><em>Note: I know of very few use cases for global ##temp tables. Fellow SQL Server MVP Erland Sommarskog mentions them briefly in <\/em><a href=\"https:\/\/learn.microsoft.com\/en-us\/answers\/questions\/767719\/temp-tables-vs-globaltemp-tables-why-would-i-ever\" target=\"_blank\" rel=\"noreferrer noopener\"><em>this Microsoft Q&amp;A<\/em><\/a><em>.<\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Wrong schema<\/h4>\n\n\n\n<p>The object could be in <a href=\"https:\/\/www.red-gate.com\/simple-talk\/blogs\/securing-access-administrator\/\" target=\"_blank\" rel=\"noreferrer noopener\">dbo<\/a> but you are specifying a different schema, or vice-versa.<\/p>\n\n\n\n<p>It could also be that you are not specifying a schema in your object reference at all, but you <a href=\"https:\/\/sqlblog.org\/2019\/09\/12\/bad-habits-to-kick-avoiding-the-schema-prefix\" target=\"_blank\" rel=\"noreferrer noopener\">nearly always should<\/a>, aside from this <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/t-sql-programming-sql-server\/schema-prefix-at-stack-overflow\/\" target=\"_blank\" rel=\"noreferrer noopener\">convenient exception<\/a>. When you don\u2019t specify the schema, this is what happens:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>SQL Server will check your default schema first. If it finds the object, cool!<br><br><\/li>\n\n\n\n<li>If the object isn\u2019t in your default schema, but it is in dbo, cool!<br><br><\/li>\n\n\n\n<li>The other way around doesn\u2019t work. If it doesn\u2019t find the object in your default schema or dbo, it\u2019s not going to search all the other schemas, even the ones you have access to. This is why you should (again, almost) always be explicit.<\/li>\n<\/ul>\n<\/div>\n\n\n<p><br><strong><em>Enjoying this article? You may also be interested in:<\/em><\/strong><\/p>\n\n\n<ul class=\"wp-block-latest-posts__list wp-block-latest-posts\"><li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/managed-identities-in-sql-server-2025-a-complete-guide\/\">What are managed identities in SQL Server 2025? A complete guide<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/how-to-utilize-testing-to-ensure-a-successful-cloud-migration\/\">How to utilize testing to ensure a successful cloud migration<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/what-is-chunking-and-how-does-it-apply-to-vectors-in-sql-server-2025\/\">What is chunking, and how does it apply to vectors in SQL Server 2025?<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/www.red-gate.com\/simple-talk\/cloud\/why-over-communication-is-critical-to-the-success-of-a-cloud-migration\/\">Why over-communication is critical to the success of a cloud migration<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/www.red-gate.com\/simple-talk\/ai\/how-to-get-80-of-gpt-4s-value-for-20-of-the-cost-5-tips-for-reducing-ai-spend\/\">How to get 80% of GPT-4\u2019s value for 20% of the cost (5 tips for reducing AI spend)<\/a><\/li>\n<\/ul>\n\n\n<h4 class=\"wp-block-heading\"><br>Wrong database<\/h4>\n\n\n\n<p>This is actually pretty common. You either created the object in the wrong database (typically in master), or you are not in the database you thought you were (also, typically, in master). Make sure your <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/tools-sql-server\/ssms-the-query-window-keyboard-shortcuts\/\" target=\"_blank\" rel=\"noreferrer noopener\">query window<\/a> sets the context to the right database and that your application includes the database name in the connection string. It might work fine until, for example, someone recreates a login or changes its default database.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Wrong server\/instance<\/h4>\n\n\n\n<p>There are several flavors here:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>You may have created the object in SQL Server Management Studio, then connected your app (or a different query window) to the wrong instance. You might have a default instance alongside a named instance (e.g. <code>\\SQLEXPRESS<\/code>), and SSMS is connected to one, but the app is connected to the other.<em> I talk about this scenario and others like it in <\/em><a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/t-sql-programming-sql-server\/when-an-update-doesnt-update\/\" target=\"_blank\" rel=\"noreferrer noopener\"><em>When an update doesn\u2019t update<\/em><\/a><em>.<\/em><br><br><\/li>\n\n\n\n<li>An all-too common one here is when using SQL Server Express Edition and the deprecated <code>UserInstances<\/code>\/<code>AttachDbFileName<\/code> settings, where you have created the object in one instance, then the app or SQL Server Management Studio conveniently created a brand new one for you. <em>I talk about this ill-fated \u201cfeature\u201d here in <\/em><a href=\"https:\/\/thwack.solarwinds.com\/groups\/data-driven\/b\/blog\/posts\/bad-habits-using-attachdbfilename\" target=\"_blank\" rel=\"noreferrer noopener\"><em>Bad Habits: Using AttachDbFIleName<\/em><\/a><em>.<\/em><br><br><\/li>\n\n\n\n<li>You created a synonym or view and the object it points to has since moved (or, in the case of a synonym, it never existed).<br><br><\/li>\n\n\n\n<li>You are running SSMS in <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/tools-sql-server\/sql-server-sqlcmd-basics\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQLCMD mode<\/a> and are in the wrong :CONNECT context.<\/li>\n<\/ul>\n<\/div>\n\n\n<h4 class=\"wp-block-heading\">Conclusion<\/h4>\n\n\n\n<p>Those are the most typical reasons I\u2019ve seen for the invalid object name error. Do you know of other scenarios I haven\u2019t covered? Let me know down in the comments.<\/p>\n\n\n\n<section id=\"faq\" class=\"faq-block my-5xl\">\n    <h2>FAQs: Common SQL Server Problems: Invalid Object Name<\/h2>\n\n                        <h3 class=\"mt-4xl\">1. What does \u2018Invalid object name\u2019 mean in SQL Server?<\/h3>\n            <div class=\"faq-answer\">\n                <p>It means SQL Server cannot find the referenced object, often due to typos, missing objects, or incorrect schema\/database context.<\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">2. How do I fix an invalid object name error in SQL Server?<\/h3>\n            <div class=\"faq-answer\">\n                <p><span style=\"font-size: 1rem\">Check for spelling mistakes, confirm the object exists, ensure you\u2019re in the correct database and schema, and verify your connection context.<\/span><\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">3. Can case sensitivity cause invalid object name errors in SQL Server?<\/h3>\n            <div class=\"faq-answer\">\n                <p>Yes, because in case-sensitive databases, object names must match exactly in case. For example, <code>dbo.Users<\/code> and <code>dbo.users<\/code> are different.<\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">4. Why does this error occur after creating a stored procedure?<\/h3>\n            <div class=\"faq-answer\">\n                <p>SQL Server allows deferred name resolution in procedures, so missing objects won\u2019t trigger errors until execution.<\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">5. How can I prevent invalid object name errors?<\/h3>\n            <div class=\"faq-answer\">\n                <p>Use tools like <a href=\"https:\/\/www.red-gate.com\/products\/sql-prompt\/\" target=\"_blank\" rel=\"noopener\">Redgate SQL Prompt<\/a> for IntelliSense and auto-complete, always specify schema names, and double-check your database context.<\/p>\n            <\/div>\n            <\/section>\n","protected":false},"excerpt":{"rendered":"<p>Learn why SQL Server shows \u2018Invalid object name\u2019 errors and how to fix them. Common causes include typos, missing objects and wrong schema.&hellip;<\/p>\n","protected":false},"author":341115,"featured_media":108062,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143523,53,143524],"tags":[159371,4150,4151],"coauthors":[158980],"class_list":["post-108057","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-databases","category-featured","category-sql-server","tag-common-issues-in-sql-server","tag-sql","tag-sql-server"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/108057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/341115"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=108057"}],"version-history":[{"count":11,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/108057\/revisions"}],"predecessor-version":[{"id":108502,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/108057\/revisions\/108502"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media\/108062"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=108057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=108057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=108057"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=108057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}