sql server invalid object name - but tables are listed in SSMS tables list

Sql ServerSsms

Sql Server Problem Overview


I am attempting to create a Stored Procedure for a newly created database. However the SSMS intellisense does not recognize more than half of the tables which have been created.

For example whilst in the left hand column under tables I have a table dbo.Room, when I type "dbo." in the new query window, that table is not listed, in fact only 17 out of 37 tables are listed.

I can see no difference between the tables listed by intellisense and those not. If I manually type dbo.Room, it is underlined, with an error of

> Invalid Object Name 'dbo.Room'..

Have I missed something in setting up the tables?

UPDATE: I have tried refresh of the tables list (several times)

Sql Server Solutions


Solution 1 - Sql Server

Try:

Edit -> IntelliSense -> Refresh Local Cache

This should refresh the data cached by Intellisense to provide typeahead support and pre-execution error detection.

NOTE: Your cursor must be in the query editor for the IntelliSense menu to be visible.

Solution 2 - Sql Server

Make sure that the selected DB is the one where the table is. I was running the Script on Master. In my case, I had to switch to hr_db.

enter image description here

Rookie mistake but, could help someone.

Solution 3 - Sql Server

Ctrl + Shift + R refreshes intellisense in management studio 2008 as well.

Solution 4 - Sql Server

once you create a new SQL Server object, your newly created object does not get updated in the IntelliSence Local Cache and due to this, it shows red line underneath that object. So you just need to refresh SSMS IntelliSence Local Cache and once you refresh it, IntelliSence will automatically add newly created object in the cache and the red line will disappear. try this

Edit -> IntelliSense -> Refresh Local Cache or Ctrl + Shift + R

enter image description here

Solution 5 - Sql Server

In my case, the IntelliSense cache was listing object information for an entirely different database. If I clicked the "New Query" button in SSMS, it would open a query to my default catalog on the server and that query editor would always only use that database. Refreshing the cache didn't change anything. Restarting SSMS didn't change anything. Changing the database didn't change anything.

I ended up creating a query by right-clicking on the database I actually wanted to use and choosing "New Query" from that context menu. Now SSMS uses the correct objects for IntelliSense.

Solution 6 - Sql Server

Are you certain that the table in question exists?

Have you refreshed the table view in the Object Explorer? This can be done by right clicking the "tables" folder and pressing the F5 key.

You may also need to reresh the Intellisense cache.

This can be done by following the menu route: Edit -> IntelliSense -> Refresh Local Cache

Solution 7 - Sql Server

The solution is:

  • Click menu Query,
  • then click 'Change Database'.
  • Select your appropriate database name.

That's it.

Solution 8 - Sql Server

Same problem with me when I used this syntax problem solved.

Syntax:

Use [YourDatabaseName]
Your Query Here

Solution 9 - Sql Server

Even after installing SP3 to SQL Server 2008 Enterprise this is still an "issue." Ctrl+Shift+R like everyone has been saying solved this problem for me.

Solution 10 - Sql Server

In azure data studio press "cmd+shift+p" and type "intellisense", then you will see an option to refresh intellisense cache.

Solution 11 - Sql Server

Solved for SSMS 2016.

Had a similar problem, but Intellisense was not in Edit menu.

What seemed to fix it was turning Intellisens on and off, right click on the SQL editor and click 'Intellisense Enabled'. Right click again on 'Intellisense Enabled' to turn it back on again. Ctr Q, I also does this.

This solved the problem, and also I know get the Intellisense on the Edit menu.

Solution 12 - Sql Server

did you try: right click the database, and click "refresh"

Solution 13 - Sql Server

I just had to close SMSS and reopen it. I tried Refresh Local Cache and that didn't work.

Solution 14 - Sql Server

I realize this question has already been answered, however, I had a different solution:

If you are writing a script where you drop the tables without recreating them, those tables will show as missing if you try to reference them later on.

Note: This isn't going to happen with a script that is constantly ran, but sometimes it's easier to have a script with queries to reerence than to type them everytime.

Solution 15 - Sql Server

I ran into the problem with : ODBC and SQL-Server-Authentication in ODBC and Firedac-Connection

Solution : I had to set the Param MetaDefSchema to sqlserver username : FDConnection1.Params.AddPair('MetaDefSchema', self.FDConnection1.Params.UserName);

The wikidoc sais : MetaDefSchema=Default schema name. The Design time code >>excludes<< !! the schema name from the object SQL-Server-Authenticatoinname if it is equal to MetaDefSchema.

without setting, the automatic coder creates : dbname.username.tablename -> invalid object name

With setting MetaDefSchema to sqlserver-username : dbname.tablename -> works !

See also the embarcadero-doc at : http://docwiki.embarcadero.com/RADStudio/Rio/en/Connect_to_Microsoft_SQL_Server_(FireDAC)

Hope, it helps someone else..

regards, Lutz

Solution 16 - Sql Server

Don't forget to create your migrations after writing the models

Solution 17 - Sql Server

For me I had rename from

[Database_LS].[schema].[TableView]

to

[Database_LS].[Database].[schema].[TableView]

Solution 18 - Sql Server

I was working on Azure SQL Server. For storing the data I used table values param like

DECLARE @INTERMEDIATE_TABLE3 TABLE { 
     x int;
 }

I discovered the error in writing on the queries

SELECT
    *
FROM 
    [@INTERMEDIATE_TABLE3]
WHERE 
    [@INTERMEDIATE_TABLE3].[ConsentDefinitionId] = 3

While querying the columns, it's okay to wrap it with braces like [@INTERMEDIATE_TABLE3].[ConsentDefinitionId] but when referring to just the table valued param, there should be no params. So it should be used as @INTERMEDIATE_TABLE3

So the code now must be changed to

SELECT
    *
FROM 
    @INTERMEDIATE_TABLE3
WHERE 
    [@INTERMEDIATE_TABLE3].[ConsentDefinitionId] = 3

Solution 19 - Sql Server

In my case, I was trying to alter a stored procedure that didn't exist in the database, after creating it and refreshing local cache, it worked

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRichbitsView Question on Stackoverflow
Solution 1 - Sql ServerAdam RobinsonView Answer on Stackoverflow
Solution 2 - Sql Server10110View Answer on Stackoverflow
Solution 3 - Sql ServerZielynView Answer on Stackoverflow
Solution 4 - Sql ServerNagaraj SView Answer on Stackoverflow
Solution 5 - Sql ServerBacon BitsView Answer on Stackoverflow
Solution 6 - Sql ServerJohn SansomView Answer on Stackoverflow
Solution 7 - Sql ServerTono FRLView Answer on Stackoverflow
Solution 8 - Sql Serveruser5093161View Answer on Stackoverflow
Solution 9 - Sql ServerdemmithView Answer on Stackoverflow
Solution 10 - Sql Serverpavel_orekhovView Answer on Stackoverflow
Solution 11 - Sql ServerEric YeomanView Answer on Stackoverflow
Solution 12 - Sql ServerKM.View Answer on Stackoverflow
Solution 13 - Sql ServerstealthysnacksView Answer on Stackoverflow
Solution 14 - Sql ServerTroy LobergerView Answer on Stackoverflow
Solution 15 - Sql ServerLutzView Answer on Stackoverflow
Solution 16 - Sql ServermgPePeView Answer on Stackoverflow
Solution 17 - Sql ServerPaul TotzkeView Answer on Stackoverflow
Solution 18 - Sql ServerSriharsha g.r.vView Answer on Stackoverflow
Solution 19 - Sql ServerGonzalo CavazosView Answer on Stackoverflow