Introduction to Azure SQL DB, Part 2: Setting up Azure SQL

Continuing from Introduction to Azure SQL Database, Part 1: Overview

If you're following along, I've covered how to setup Azure CLI in a separate post.

Now let's get started setting up our first Azure SQL DB with Azure CLI. I particularly like using Azure CLI in interactive mode because of tab completion. You can launch into Azure CLI interactive using:


az interactive

Creating your Resource Group

If you haven't created a Resource Group to contain all your resources for testing Azure SQL, you can do so now. For more information on Resource Groups you can read the overview of Azure Resource Manager.


az group create --name "insert group name here" --location "choose a default location for your group resources"

Azure CLI - Create Resource Group

Creating the Azure SQL Server

Creating the actual SQL Server is no more complex than creating the Resource Group - just a couple more parameters involved such as username, password, server name.

Keep in mind that we're first creating the Azure SQL Server which is a logical host for our Azure SQL Database. We can, of course, host multiple databases within our Azure SQL Server.


az sql server create --admin-user "admin name" -p "admin password" -g "group name" -l "location" -n "SQL Server name"

Azure CLI - Create Azure SQL Server

Once you've issued your az sql server create command you should be returned a handy success message in JSON.

Azure CLI - Create SQL Server Success

Add a firewall rule

Azure puts up a DENY ALL firewall rule by default; so before we start doing cool stuff like adding databases to our SQL Server - we have to first allow ourselves access to the logical server.

Use your own IP address as both the beginning and end IP address.


az sql server firewall-rule create --name "firewall rule name" --server "name of the SQL server" --resource-group "name of the resource group" --start-ip-address x.x.x.x --end-ip-address x.x.x.x 

Azure CLI - Create firewall rule

Create your shiny new Azure SQL database

The last step to getting your Azure SQL database running is to create it on-top of the Azure SQL Server that we created in the previous steps.

The Azure SQL database we probably want to setup is a Basic instance - which has a max size of 2GB and maximum 5 Database Transaction Units (DTU).


az sql db create -n "name of the SQL database" -g "name of the resource group to add the database to" -s "name of the SQL Server to add the database to" --service-objective Basic

Azure CLI - Create Azure SQL database

That's all there is to it. You now have a functional database to begin developing on. You can scale it up as necessary if you decide to take your application into production, add Analytics, Threat Detection, etc... The choice is yours.

Next up: Connecting to Azure SQL and using Node.js