422

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)

DineshDB
  • 5,998
  • 7
  • 33
  • 49
Richbits
  • 7,344
  • 8
  • 33
  • 38
  • 13
    Answer that works: `[DatabaseName].[Schema].[TableName]` [SO: Invalid Object Name sql](http://stackoverflow.com/a/24621331/1608670) – Ivan Chau Jan 24 '16 at 13:56

19 Answers19

914

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.

ShadowFlame
  • 2,996
  • 5
  • 26
  • 40
Adam Robinson
  • 182,639
  • 35
  • 285
  • 343
  • Thanks, I suspect that this would have solved. I actually restarted SSMS and found that that solved. Probably should have done that in first place, but my initial thought was I had done something wrong in setup. – Richbits Sep 01 '09 at 13:54
  • 8
    Does Intellisense/SSMS refresh itself periodically? Or must this always be a manual process? (I've got my guess based on SSMS in 2005, but one can always hope.) – Philip Kelley Sep 01 '09 at 14:26
  • 59
    unbelievable that in 2012 you need to do this. Couldn't they update Intellisense every few seconds automatically? – Matthew Lock Feb 29 '12 at 05:51
  • 8
    That may require hitting the database and pulling the table/view definitions every few seconds. – jinglesthula Dec 18 '12 at 18:54
  • 1
    @jinglesthula Every few seconds might be much, but adding a new object/column seems fine to me. – anar khalilov Apr 03 '14 at 12:15
  • 11
    NOTE: Your cursor must be in the query editor for the IntelliSense menu to be visible. – bradlis7 Dec 11 '14 at 15:58
  • 6
    @jinglesthula: That would save *me* hitting the database server! – Paul Jan 16 '17 at 09:57
  • This doesn't appear to work on linked servers, though - at least, it didn't for me – Jon Story May 02 '18 at 13:45
  • Thanks, the refresh worked. It would be great if, at the least, IntelliSense would give you a light bulb like in Visual Studio to offer suggested fixes. – midoriha_senpai Aug 15 '18 at 16:05
  • 1
    Short cut combo: Ctrl+Shift+R (SSMS 17) – G Cadogan Nov 14 '19 at 18:08
  • This is crazy! The table was actually causing me problems with Linq within an application (not SSMS) that I was working on - returning weird results when it should have just been empty & causing exceptions. When I tried this in SMSS, the problem went away! Sorry to ruin the magic "666" upvotes but I have to add one just for that... – komodosp Jan 10 '20 at 12:49
  • @thanos.a Is still valid in my version 17.6. You really should add a version number that this doesn't work in. – IT Alex Feb 19 '20 at 20:14
  • @IT Alex I have checked it in 18.4 and the menu is valid. – thanos.a Feb 21 '20 at 07:31
  • 1
    Works in v18.5 in 2020. They still don't auto update intellisense. – MasterJoe May 26 '20 at 05:01
  • Thank you. Might be a setting somewhere to auto-update/refresh. Let me know anybody found that option. – Anoj Aug 14 '20 at 15:00
  • In VS Code, you can also do CTRL+SHIFT+P and search for "MS SQL: Refresh Intellisense Cache" to refresh (assuming mssql extension is installed of course). – user2315856 Oct 16 '20 at 13:54
  • It works! I wonder why there is no clear error message or a simple suggestion by SMSS to make a refresh! – Merna Mustafa Sep 09 '21 at 06:09
  • 1
    It's 2023, and we still need to do this: Version 18.12.1 – EmpathicSage Jan 26 '23 at 13:26
130

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.

10110
  • 2,353
  • 1
  • 21
  • 37
  • 10
    I'm not sure it's a rookie mistake to be honest, as whenever you reconnect the server it for some reason switches to "master" for no obvious reason. :) – Chris Rae Dec 28 '18 at 04:48
  • If that were the case and the query did not fully qualify the table names, the code wouldn't execute. I believe the OP was describing false positive error detection when the problem you've described was not a contributing factor. (Certainly, I had already ruled out the possibility when I went searching and wound up here.) – Dodecaphone Apr 15 '19 at 18:51
  • Exactly my issue. There's no indication from SMS that it's changed the database context, or any other clue. – Daniel Black Apr 08 '20 at 20:18
  • 4
    @ChrisRae: That's because `master` is set as the default database for your user login. Just change that using `sp_defaultdb` to another database to have the other database being selected in SSMS when you log in. (Can also be set in SSMS by `Security > Logins > your user login > Properties > Default database`) – AxD Apr 12 '20 at 23:20
  • 1
    Just to add to this. Make sure the table is referencing the same schema, i.e. "dbo." schema. – pbou Nov 24 '22 at 10:48
96

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

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Zielyn
  • 1,026
  • 6
  • 4
44

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

Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
  • 1
    I don't have this feature ... when I press ctrl + shift + R nothing changes – Ibrahim Amer Sep 09 '15 at 17:21
  • 5
    @IbrahimAmer Your cursor must be in a query editor for the Intellisense menu option to be available. If the intellisense menu option is not available the shortcut will do nothing. – Rachael Oct 02 '15 at 13:35
19

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.

Bacon Bits
  • 30,782
  • 5
  • 59
  • 66
10

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

Himanshu
  • 31,810
  • 31
  • 111
  • 133
John Sansom
  • 41,005
  • 9
  • 72
  • 84
7

The solution is:

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

That's it.

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
Tono FRL
  • 81
  • 1
  • 2
7

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

Syntax:

Use [YourDatabaseName]
Your Query Here
5

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.

Himanshu
  • 31,810
  • 31
  • 111
  • 133
demmith
  • 59
  • 1
  • 2
  • I don't have this feature ... when I press ctrl + shift + R nothing changes – Ibrahim Amer Sep 09 '15 at 17:21
  • @IbrahimAmer Your cursor must be in a query editor for the Intellisense menu option to be available. If the intellisense menu option is not available the shortcut will do nothing. – Rachael Oct 02 '15 at 13:36
4

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

pavel_orekhov
  • 1,657
  • 2
  • 15
  • 37
3

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.

Troy Loberger
  • 347
  • 1
  • 8
  • 28
3

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.

Eric Yeoman
  • 1,036
  • 1
  • 14
  • 31
2

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

KM.
  • 101,727
  • 34
  • 178
  • 212
  • Yes, I've tried that, I am sure it is there, I can add records and modify etc.Just did a Select * from dbo.Room and whilst I still have the underline it outputted the contents of the table. I'm gonna try a reboot. – Richbits Sep 01 '09 at 13:46
  • Refresh did not worked for me – Kiran Antony Jul 06 '23 at 14:29
2

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

stealthysnacks
  • 1,091
  • 1
  • 12
  • 16
0

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

Lutz
  • 11
  • 1
0

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

mgPePe
  • 5,677
  • 12
  • 52
  • 85
0

For me I had rename from

[Database_LS].[schema].[TableView]

to

[Database_LS].[Database].[schema].[TableView]
Paul Totzke
  • 1,470
  • 17
  • 33
0

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
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sriharsha g.r.v
  • 456
  • 5
  • 13
0

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

fluid undefined
  • 364
  • 2
  • 6