DEV Community

Simon Foster
Simon Foster

Posted on • Originally published at funkysi1701.com on

SQL with Visual Studio Code

Writing SQL queries is typically done with SQL Management Studio (SSMS). However this tool is a bit of a beast so let’s look at how you could use Visual Studio Code instead.

Visual Studio Code is a free text editor but it is so much more than just a text editor. VS Code can be downloaded from https://code.visualstudio.com/Download

To work with SQL Server download the mssql extension. Press CTRL+SHIFT+P and then Select Install Extension and type mssql.

Intellisense in Visual Studio Code is brilliant, better than SSMS. Lets look at how to get it all set up.

Create a new file and set the language type to SQL (Press CTRL+K,M )

Open the command palette, *CTRL+SHIFT+P * and type SQL to show the mssql commands. Select the Connect command.

Then select Create Connection Profile , this creates a profile to connect with your SQL Server. Follow the prompts to get it all setup.

Look in the bottom right corner of the status bar and you should see you are connected.

Now if you type sql you will see a long list of SQL code snippets that you could use.

Choose a snippet to create, and edit it as required. When you are happy press *CTRL+SHIFT+E * to execute.

This is basically all there is to it. However this is an incredibly powerful way of working, the intellisense instantly tells you what database objects you can use in your query and there is a wealth of different snippets you can use.

When returning data you get a similar view to SSMS but you can save as Excel, CSV or JSON.

SSMS is a very graphical way of doing things, you can double click a table and see its columns or indexes. VS Code relies on TSQL commands but you have access to exactly the same information.

For more information about VS Code and the mssql extension check out https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-develop-use-vscode

The post SQL with Visual Studio Code appeared first on Funky Si's Tech Talk.

Top comments (0)