How to create an Azure SQL database

In this azure tutorial, we will discuss How to create an Azure SQL database. Apart from this, we will also discuss on the below topics

  • Advantages of Azure SQL database
  • Microsoft Azure SQL Database Step By Step
  • Query the SQL database in Azure
  • How to create an Azure SQL database using PowerShell
  • Why Create an SQL database on Azure

How to create an Azure SQL database

Before discussing the topic How to create an Azure SQL database, let’s discuss a few things on the Microsoft Azure SQL Database.

Microsoft Azure SQL Database is a managed cloud database that uses the SQL Server database engine in the Azure Cloud platform. It becomes easier for the developers/programmers to develop their products as there is less involvement in the maintenance part of the product.

It supports modern cloud applications with managed database service.

Advantages of Azure SQL database

  • Azure SQL comes with High-Speed performance and with very Minimal Down Time.
  • Another big advantage is Azure SQL is scalable in nature.
  • The pricing structure of Azure SQL is the pay as you go, model, meaning pay that much how much you are actually using.
  • Azure SQL is highly available. This is another big advantage with the Azure SQL.

SQL Azure Costs

For an entry-level, You have to pay $4.99 per database per month with maximum storage set at 150 GB per database.

History of Azure SQL

Azure SQL is originally announced in the year of 2009 but actually it got released on the year of 2010.

Let’s discuss here Microsoft Azure SQL Database Step By Step.

Microsoft Azure SQL Database Step By Step

Follow the below steps to create the Azure SQL database using the Azure Portal.

Step-1: Login to the Azure portal (https://portal.azure.com/)

Step-2: Search for Azure SQL and select it .

Microsoft Azure SQL Database Step By Step

Step-3: Click on the Add button On the Azure SQL page.

How to create an Azure SQL database

Step-4: On the Select SQL deployment option window, click on the Create button from the SQL database option.

azure sql database tutorial

Step-5: On the Basics, Fill the below details.

  • Subscription: Select the correct subscription.
  • Resource group: Create a new resource group by clicking on the Create new link.
  • Database name: Provide a meaning full database name.

Server: Click on the Create new link to create a new server. Enter the below details on the New server form.

  • Server name: Enter a unique server name
  • Server admin login: Enter azure user.
  • Password: Enter a password and enter it again in the Confirm password field.
  • Location: Choose a location here

Click on the OK button

Create an Azure SQL database how to create

Compute + storage: It will load a default one. if you want to reconfigure the defaults, select Configure database link.

On the Configure page, you can choose the below details.

  • You can change the Compute tier from Provisioned to Serverless.
  • Change the settings for vCores and Data max size.
  • Click on the Change configuration button to change the hardware generation.

Now click on the Apply.

how to Create an Azure SQL database

Click on the Next:Networking> button to go the Networking tab.

In the Networking tab, Choose the below options

  • Select the Connectivity method as Public endpoint.
  • Choose the No option for Allow Azure services and resources to access this server.
  • Select Yes option for Add current client IP address.
How and Why To Create an SQL Database on Azure

Click on Next : Additional settings > button to go to Additional settings page

Select the Sample option for Use existing data

Click on the Review + Create button.

Why to create an Azure SQL database

Now click on the Create button which will create the Azure SQL database.

Note: Do not forget to read the terms properly before clicking on the Create button.

Why to configure an Azure SQL database

This is how we can create Microsoft Azure SQL Database Step By Step.

Query the SQL database in Azure

Once your data base is created by using the above steps, now time to query the database.

To query the database follow the below steps.

Step-1: Login to the Azure portal and search for SQL databases and select it.

Query the SQL database in Azure

Step-2: From the SQL databases window select the database you have created.

Step-3: Select the Query editor (preview) option from the left menu from the database page.

Step-4: Enter your credentials under SQL server authentication which you have generated earlier on the New server page and then click on the OK button.

Step-5: Enter your SQL query in the query editor and then click on the Run button to execute the query. It will show the output at the Results pane.

How to create an Azure SQL database using PowerShell

Let’s discuss how to create an Azure SQL database using PowerShell. Follow the below steps

Set the subscription details

Use the below PowerShell cmdlet to set the subscription details.

$MysubscriptionId = '1cdf4300-dee5-4518-9c9c-feaa72a5cbd1'
Set-AzContext -SubscriptionId $MysubscriptionId 
How to create an Azure SQL database using PowerShell

Creation of the Resource group

Use the below PowerShell cmdlet to create the resource group.

$MyresourceGroupName = "newresgroup-$(Get-Random)"
$Mylocation = "Eastus"
$MyresourceGroup = New-AzResourceGroup -Name $MyresourceGroupName -Location $Mylocation
create an Azure SQL database using PowerShell

Creation of server

To create the server, use the below PowerShell cmdlet.

$MyresourceGroupName = "newresgroup-$(Get-Random)"
$NewserverName = "myservernew-$(Get-Random)"
$Mylocation = "Eastus"
$NewadminSqlLogin = "SqlAdmin"
$Newpassword = "Password@xyz123"

$Myserver = New-AzSqlServer -ResourceGroupName $MyresourceGroupName `
    -ServerName $NewserverName `
    -Location $Mylocation `
    -SqlAdministratorCredentials $(New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $NewadminSqlLogin, $(ConvertTo-SecureString -String $Newpassword -AsPlainText -Force))
Creation of an Azure SQL database using PowerShell

Creation of Firewall Rule

We can use the below PowerShell cmdlet to create the firewall rule

$MyresourceGroupName = "newresgroup-$(Get-Random)"
$NewserverName = "myservernew-$(Get-Random)"
$NewstartIp = "0.0.0.0"
$NewendIp = "0.0.0.0"

$MyserverFirewallRule = New-AzSqlServerFirewallRule -ResourceGroupName $MyresourceGroupName `
    -ServerName $NewserverName `
    -FirewallRuleName "AllowedIPs" -StartIpAddress $NewstartIp -EndIpAddress $NewendIp
powershell create sql database

Create a blank Database

Create the blank database using the below PowerShell cmdlet

$MyresourceGroupName = "newresgroup-$(Get-Random)"
$NewserverName = "myservernew-$(Get-Random)"
$NewdatabaseName = "mynewdb36845"

$mydatabase = New-AzSqlDatabase  -ResourceGroupName $MyresourceGroupName `
    -ServerName $NewserverName `
    -DatabaseName $NewdatabaseName `
    -RequestedServiceObjectiveName "S0"
powershell create sql database azure

Run the below complete script to create azure sql database using PowerShell in Azure

$MysubscriptionId = '1cdf4300-dee5-4518-9c9c-feaa72a5cbd1'

$MyresourceGroupName = "newresgroup-$(Get-Random)"
$Mylocation = "Eastus"
#Admin login and password for your server
$NewadminSqlLogin = "SqlAdmin"
$Newpassword = "Password@xyz123"

$NewserverName = "myservernew-$(Get-Random)"
$NewdatabaseName = "mynewdb36845"

$NewstartIp = "0.0.0.0"
$NewendIp = "0.0.0.0"
Set-AzContext -SubscriptionId $MysubscriptionId 
$MyresourceGroup = New-AzResourceGroup -Name $MyresourceGroupName -Location $Mylocation
$Myserver = New-AzSqlServer -ResourceGroupName $MyresourceGroupName `
    -ServerName $NewserverName `
    -Location $Mylocation `
    -SqlAdministratorCredentials $(New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $NewadminSqlLogin, $(ConvertTo-SecureString -String $Newpassword -AsPlainText -Force))
$MyserverFirewallRule = New-AzSqlServerFirewallRule -ResourceGroupName $MyresourceGroupName `
    -ServerName $NewserverName `
    -FirewallRuleName "AllowedIPs" -StartIpAddress $NewstartIp -EndIpAddress $NewendIp
$mydatabase = New-AzSqlDatabase  -ResourceGroupName $MyresourceGroupName `
    -ServerName $NewserverName `
    -DatabaseName $NewdatabaseName `
    -RequestedServiceObjectiveName "S0" 
powershell script to create azure sql database

Now after running the above script you can login to the Azure portal and check if the SQL database is created

how to create azure sql database free using powershell

Why to Create an SQL database on Azure

Maintaining the on-premise environment is a headache. You can easily create the SQL database in Azure and no headache for the infrastructure.

You can easily move the databases between different machines on the cloud environments.

The main benefits of creating an Azure SQL database are

  • You can use the unlimited storage
  • Quick and easy access
  • Enhanced security features
  • Backups and restores are easy

You may like following Azure tutorials

Conclusion

In this Azure tutorial, We discussed

  • Advantages of Azure SQL database
  • Microsoft Azure SQL Database Step By Step
  • Create an Azure SQL database
  • Query the SQL database in Azure
  • How to create an Azure SQL DB using PowerShell
  • Why to Create an SQL DB on Azure

Leave a Comment