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!!
- Login to Azure Portal.
- After login, you will land on the Dashboard. Click "New" in the side menu.
- Now, select Database >> SQL Database.
- 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.
- Getting ready to start.
- 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.
- Enter your IP from where you want to access the database. Also, you can set subnet IP range.
- 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.
- Search for mssql in Extension search bar and Install it.
Reload VS Code and then open a "New File" from File menu or by pressing Ctrl + N.
- Now, press F1. You will get a search menu on the top of the screen. Search for MS SQL: Connect
- Now, it will prompt to set language; press Yes.
- Select SQL.
- Create a connection profile in order to connect your file with the database.
- Follow the prompts to specify the connection properties for the new connection profile. After specifying each value, press ENTER to continue.
The following table describes the Connection Profile properties.
Setting | Description |
Server name | The 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 name | The database that you want to use. For purposes of this tutorial, don't specify a database and press ENTER to continue. |
Username | Enter 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 profile | The Connection Profile name. For example, you could name the profile localhost profile |
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.
Now, you can write and run queries using Ctrl + Shift + E.
Create table
Insert data
Select query
The result can be saved as CSV, JSON, and Excel.
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