Azure SQL provisionig using CLI
The Azure CLI 2.0 is Azure’s new command-line experience for managing Azure resources. You can use it in your browser with Azure Cloud Shell, or you can install it on macOS, Linux, and Windows and run it from the command line.
Learning Azure CLI is pretty simple specially if you are comfort with PowerShell. Following script block shows how to create SQL server with database using Azure CLI
# Set an admin login and password for your database
export adminlogin=ServerAdmin
export password=ChangeYourAdminPassword1
# other parameters
export servername=clisqlserver1
export myResourceGroup=clisqlrg
export location=westeurope
# The ip address range that you want to allow to access your DB
export startip=0.0.0.0
export endip=0.0.0.0
# Create a resource group
az group create --name $myResourceGroup --location $location
# Create a logical server in the resource group
az sql server create --name $servername \
--resource-group $myResourceGroup \
--location $location \
--admin-user $adminlogin \
--admin-password $password
# Configure a firewall rule for the server
az sql server firewall-rule create --resource-group $myResourceGroup \
--server $servername -n AllowYourIp --start-ip-address $startip --end-ip-address $endip
# Create a database in the server
az sql db create --resource-group $myResourceGroup \
--server $servername --name mySampleDatabase \
--sample-name AdventureWorksLT \
--service-objective S0
# You can list all the SQL Server as formatted output (tsv, json, jsonc, table)
az sql db list -g $myResourceGroup -s $servername -o jsonc
# Cleanup the deployment
az group delete --name myResourceGroup
Related Posts
- Deploy SonarQube as Azure Web App Container
- Azure VNET provisioning using CLI
- Design VM Scale Sets - 1
- Design solutions using virtual machines - 2
- Design solutions using virtual machines - 1
About Ajeet Chouksey

Ajeet Chouksey
Subscribe via Email
Recent Posts