Search⌘ K
AI Features

IntelliSense and Snippets

Explore how to use IntelliSense and customizable code snippets in Azure Data Studio to streamline SQL query creation and editing. Learn to navigate suggestions, accept keywords, use multi-cursor tabbing, and customize snippets for your projects.

We'll cover the following...

Introduction

Database developers typically spend a great deal of time creating and editing SQL queries, so it only makes sense to make this experience as helpful, convenient, and productive as possible. Azure Data Studio has truly reimagined how developers interact with SQL coding and related programming languages.

This is accomplished largely by focusing directly on keyboard interactions, which incorporate IntelliSense, keywords, code snippets, and database object definitions. Much of the ADS user interface is also configurable, providing customizable color themes, zoom levels, fonts, and icons, as well as busy to minimal display panels.

IntelliSense

To get started with entering SQL queries, you can either click on “New query” from the “Welcome” page, or for more context specificity, right-click on your target database in the sidebar, and choose “New Query” as shown below:

This will open a blank editing window where you can simply start typing. As you type, each keystroke may popup with IntelliSense suggestions, as shown below. Notice that the FROM keyword is highlighted in the sorted pop-up list, indicating that you only need to hit the tab key to accept the substitution.

The up and down arrows provide navigation within this pop-up list, or you can use a mouse-click directly on the desired keyword.

Code snippets

One of my favorite editing features in ADS is powered by Code Snippets. These can be a huge timesaver. They are fully integrated with IntelliSense and are user-customizable. Let’s walk through a quick snippet example.

As an additional reference, we have linked some content in the appendix that demonstrates using snippets in Azure Data Studio

Let’s say you wanted to create a table. By typing “createtable”, you will see the camel cased snippet sqlCreatTable pop-up. Hit ‘Tab’ when highlighted or, optionally, click on the snippet in the pop-up, and you will get the “Create Table” template displayed below:

Now, you may be surprised to see four blinking cursors! This is because you are automatically placed in the process of completing the pre-defined variable placeholders. You have four blinking cursors because the first placeholder (TableName) has a total of four instances. If you were to next type “product,” the variable replacement would occur four times, and the figure below shows the result:

To move to the next defined variable, press the tab key again, and you will see the next variable highlighted (this one used for the schema name), which also has four occurrences that change simultaneously. The next tab will take you to the first table column (in this case: [Id]) and so on until all variables have been visited and likely replaced.

This default (built-in) snippet is a nice start to creating a table, but you may be thinking, “I’d like my snippet customized for our organization’s common code patterns.” Not to worry. Later in this chapter, we will cover how you can easily create your own snippets. Just like the built-in snippets, these will readily surface in your SQL editor based on the same IntelliSense-driven keystrokes.

Let’s test IntelliSense! Try to create a new query with the FROM or createable keyword and notice how IntelliSense will pop up. Hit the RUN button below to access Azure Data Studio. Here are the credentials needed to connect to the database:

  • Server: localhost
  • Authentication type: SQL Login
  • Username: SA
  • Password: Adminpass123
Hitting the run button will open up a small window
with Azure Data Studio running in it. You can also
click on the URL once the app has loaded to open it
in a new browser tab.