How to make IntelliSense understand temp tables, linked servers and synonyms

intellisensessms

I'm using SSMS 17.6 which is the latest version at the time of posting. It is supposed to have the latest official IntelliSense version. However, it underlines my scripts with red squiggles where I'm using temp tables, linked server tables and synonyms. It's difficult to edit queries because I don't get correct error detection. Everything is filled with "errors", but queries run, and the results are what I want, as expected.

I've tried a few third-party addons like SQL Complete and SSMSBoost, but they don't seem to improve IntelliSense, but rather extend the SSMS in other ways like tooltips and popups. Or maybe I just haven't figured out how to use them for improving IntelliSense.

What can I do to make IntelliSense correctly handle these things? If there is no first-party way, then what third-party extensions exist and how to configure them to improve error highlighting?

Best Answer

In short, Intellisense isn't as intelligent as its name might suggest.

Temp Tables

If you're working with temp tables across different databases or separate query windows, Intellisense doesn't think the table exists, because, well, it doesn't as far as it knows. There are usually two scenarios this occurs:

  1. At run time, we know that a first command will execute and by the time we get to running an additional command that the table will exist. But asking Intellisense to be aware of things that haven't happened yet is impossible. This usually involves the temp table being created by a different process, query window, etc. It generally only knows the scope of its own query window and objects in non-tempdb databases.

  2. If it does already exist, being aware of everything already in the tempdb is probably a performance concern (just conjecture) because things move around in there fast, from moment to moment, and it'd be hard/unlikely to get a reliable enumeration of objects that was valid for more than a few seconds. Regardless, it just doesn't know about much outside of that single query window with regards to tempdb objects.

Linked Servers

This one sort of makes sense. Do you really want Intellisense going and querying your linked servers every time you are writing queries that involve remote objects? It just doesn't know and so assumes it doesn't exist.

Synonyms

If the synonyms are referring to linked server objects, then they'll suffer from the issue described above. On their own, however, they should work fine with local database objects.

Bottom Line

Learn to ignore it, or use a different IDE if possible (one that doesn't use Intellisense). Most people seem to like Intellisense despite its flaws, but you could always turn it off completely as well.

There is a hacky work-around for temp tables at this SO question but I personally would never do that, as you're increasing the complexity and reducing readability of your code for...a red squiggly line.