When I first heard that Microsoft was going to introduce IntelliSense for SQL Server I could hardly contain my excitement. Much to my disappointment the initial version of IntelliSense left a lot to be desired. From issues like just not popping up at all, to not working on remote servers and sometimes picking incorrect entries could make it a bit tedious to use and for those of us who started out on SQL Server before the advent of IntelliSense it was easier just to revert back to good old fashioned typing from memory. I am happy to report however, that there has been great strides in IntelliSense to such an extent that if I suddenly had to live without it, I would be really really sad and my productivity would probably be affected somewhat as well.
In this article I would like to do a quick overview of IntelliSense, how to use it and also shed some light on those moments when IntelliSense just doesn’t seem to be working.
What is IntelliSense?
IntelliSense for SQL Server Management Studio which was first introduced in SQL 2008 is an intelligent code completion mechanism which increases development productivity by making code snippets, definitions and syntax checking available to you without having to leave the editor.
IntelliSense is enabled by default but can be disabled by going to Tools ➜ Options ➜ Text Editor ➜ Transact SQL ➜ IntelliSense.
If you want to use List Members and Parameter Info, also make sure that it’s enabled in the General Transact-SQL settings.
IntelliSense has a couple of main functions as you can see from the screenshot below.
Certain functions such as List Members, Parameter Info, and Quick Info List are only available when you are connected to a SQL Server instance or when you are working within a database project. Other functions such as delimiter matching and code snippets are always available.
Pressing CTRL + J will bring up a list of all members that are valid for the specific key word typed. In the below example the list displays all valid members which can be used after the keyword EXEC.
Parameter info lists the parameters required for a function or stored procedure. Typing a space following the name of a stored procedure or a parenthesis “(“ activates the parameter info option of IntelliSense. The Parameter Info not only provides the name of the required parameters but also their datatypes as well as the default values which will be used should the parameter be omitted.
The next parameter which needs to be provided is displayed in bold.
Quick info brings up a tool tip with the declaration of the item you are hovering over as long as the syntax is supported by IntelliSense.
If you are running in debug mode it will also display the current value of the expression.
IntelliSense now has the ability to match beginning and closing pairs of control flow elements such as BEGIN and END. This is very handy when you have multiple nested delimiters.
The matching BEGIN and END will be highlighted when you finish typing the last letter of both the BEGIN and END. Unfortunately it doesn’t highlight it again when you place the cursor on it again. In order to see the highlight again after you have moved on to another line of code, you have to delete a letter and retype it in either the BEGIN or END tags.
Delimiter matching applies to:
- BEGIN … END
- BEGIN TRY … END TRY
- BEGIN CATCH … END CATCH
Code snippets allows you to quickly enter commonly used code snippets into your editor. If you right click in the editor you will see two relevant menu options:
Clicking on Insert Snippet will display a drop down with possible objects to choose from.
Selecting one of these will then list all available snippets pertaining to that object type.
Selecting a snippet will insert sample code to create the object selected.
Surround With… helps you create code blocks, through the addition of BEGIN … END, IF or WHILE.
In order to add this to existing code, highlight the code you want to have inside the block and then select the code snippet to surround it with.
Troubleshooting Common Problems with IntelliSense
IntelliSense does not work
There are a couple of reasons why this could be happening.
- Firstly check if IntelliSense is enabled as explained earlier in the article. Also ensure that the Statement Completions settings are correct.
- Ensure that there is no syntax error anywhere on the page before your cursor, resolving the code error should re-activate IntelliSense.
- IntelliSense does not work inside comments, uncomment the section to be able to get the suggestions.
- IntelliSense does not work inside a quotes. Be sure to place your cursor outside of any quotes.
- Ensure that you are connected to a SQL Server Instance or a database project.
- IntelliSense is only supported on SQL Server 2008 and higher.
- IntelliSense does not work for encrypted objects.
- Not all syntax is supported. Have a look here to see if your syntax is supported.
- Are you running in SQLCMD mode? Unfortunately IntelliSense is not supported in command mode. Return to regular mode to get IntelliSense.
- IntelliSense is currently not supported for SQL Azure.
Not all objects appear in the List
When a new object is added to a database the IntelliSense cache needs to be refreshed. This can be done by pressing CTRL+SHIFT+R or clicking the menu item Edit ➜ IntelliSense ➜ Refresh Local Cache.
IntelliSense will not show you any objects to which you do not have permission. Ensure that you do indeed have permission to view the missing objects.
IntelliSense only works at the beginning of my script
Sometimes it appears as if IntelliSense stops working further down the page. This can be either because you have a syntax error a little higher up or because you exceeded the maximum script size.
You can set the maximum script size to Unlimited by going to Tools ➜ Options ➜ Text Editor ➜ Transact-SQL ➜ IntelliSense.
IntelliSense behaves funny
IntelliSense has two completion modes. You can either type SPACE to have the selected member in the list added to your code or you need to use TAB. This behavior can be toggled with the menu item Edit ➜ IntelliSense ➜ Toggle Completion Mode or by pressing CTRL+ALT+SPACE.
Unfortunately the selected completion mode does not always persist and you may have to set it for each query window. Microsoft reported that the bug was fixed, but as far as I can see it is still present in SQL 2014.
IntelliSense is not picking up my synonyms
In SQL Server 2008 IntelliSense did not recognize synonyms. This has been fixed in SQL 2012.
IntelliSense for SQL 2008 R2 stops working after VS 2010 SP1 install
If you installed Visual Studio 2010 SP1 and is using SQL Server 2008 R2, it is likely that your IntelliSense may stop working. The fix for this was released in SQL Server 2008 R2 SP1.
For more information please read this KB.
- Transact-SQL IntelliSense Overview
- Transact-SQL Syntax Supported by IntelliSense
- Completion Mode Bug
Minette currently works as a Data Platform Solution Architect at Microsoft South Africa.
View all posts by Minette Steynberg
Latest posts by Minette Steynberg (see all)
- Five ways to protect your data in Azure SQL Database - April 28, 2017
- Understanding the XML description of the Deadlock Graph in SQL Server - March 29, 2017
- Configuring the Azure SQL Database Firewall - February 28, 2017