How To Create Azure SQL Database And Access It Through Visual Studio Code

In this article, I’m going to cover how to create Azure SQL database and how you can access it through Visual Studio Code. There are some prerequisites that you should know before moving forward.

Firstly, let me be brief about Azure SQL database. It's Microsoft’s cloud database service. Based on SQL Server database technology and built on Microsoft’s Windows Azure cloud computing platform, it enables organisations to store relational data in the cloud and quickly scale the size of their databases up or down as the business needs are changed. Data is hosted, managed, and provisioned in Microsoft data centres. 

Let’s start!!

  1. Login to Azure Portal.

    Azure
  1. After login, you will land on the Dashboard. Click "New" in the side menu.

    Azure 
  1. Now, select Database >> SQL Database.

    Azure 
  1. Enter the required details, like Name, Resource group, create SQL Server, and scale the database according to your needs.

    The credentials you entered while creating SQL Server db will help you to access your database.

    Azure

    Azure 
  1. Getting ready to start.

  2. After database deployment gets finished, you will see a database’s tile on the dashboard. If not, you can navigate it through side menu. Select SQL databases, and then select demodb to add firewall settings.

    Azure

     Azure
  1. Enter your IP from where you want to access the database. Also, you can set subnet IP range.

    Azure 
  1. Now, open VS Code. You will see the Welcome Screen.

    Now, to install the extension, click on the "Extensions" icon on the side menu or Press F1 and write install extension.

    Azure

    Azure 
  1. Search for mssql in Extension search bar and Install it.

    Azure

    Reload VS Code and then open a "New File" from File menu or by pressing Ctrl + N.
  1. Now, press F1. You will get a search menu on the top of the screen. Search for MS SQL: Connect

    Azure 
  1. Now, it will prompt to set language; press Yes.

    Azure
  2. Select SQL.

    Azure 
  1. Create a connection profile in order to connect your file with the database.

    Azure 
  1. Follow the prompts to specify the connection properties for the new connection profile. After specifying each value, press ENTER to continue.

    Azure 

The following table describes the Connection Profile properties.

SettingDescription
Server nameThe SQL Server instance name. For this tutorial, use localhost to connect to the local SQL Server instance on your machine. If connecting to a remote SQL Server, enter the name of the target SQL Server machine or its IP address.
[Optional] Database nameThe database that you want to use. For purposes of this tutorial, don't specify a database and press ENTER to continue.
UsernameEnter the name of a user with access to a database on the server. For this tutorial, use the default SA account created during the SQL Server setup.
Password (SQL Login)Enter the password for the specified user.
Save Password?Type Yes to save the password. Otherwise, type No to be prompted for the password each time the Connection Profile is used.
[Optional] Enter a name for this profileThe Connection Profile name. For example, you could name the profile localhost profile


Azure 

After the file is connected to the database, you can see the server name, database name and username at the bottom right of the screen.

Azure

Now, you can write and run queries using Ctrl + Shift + E.

Create table

Azure

Insert data

Azure

Select query

Azure

The result can be saved as CSV, JSON, and Excel.

 Azure

Finally, we configured our SQL Server with few clicks on Azure, and we can access that database on VS Code. Now, we don't have to install SSMS. Just download "mssql" extension on VS Code and configure with simple steps explained above. That's it.

You can refer to the below links to know more.

  • https://docs.microsoft.com/en-us/azure/sql-database/sql-database-get-started-portal
  • https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-develop-use-vscode