How to create Azure SQL database

How to create an Azure SQL database

In this Azure tutorial, we will discuss How to create an Azure SQL Database using Azure Portal and PowerShell. Apart from this, we will also discuss the below topics

How to create Azure SQL database [Azure Portal]

Before starting the topic of How to create an Azure SQL database, you can check out the Azure SQL Database Tutorial for a better idea.

Well, it’s quite easy to create the Azure SQL database using the Azure Portal.

Follow the below steps to create a free SQL Database in Azure.

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 meaningful 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

Step-6: Compute + storage: It will load a default one. if you want to reconfigure the defaults, select the 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 Apply.

How To Create Free SQL Database In Azure

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

In the Networking tab, Choose the below options

  • Select the Connectivity method as a Public endpoint.
  • Choose the No option for Allow Azure services and resources to access this server.
  • Select the Yes option for Add current client IP address.
azure sql database create

Step-8: Click on the Next: Additional settings > button to go to the Additional settings page

  • Select the Sample option to Use existing data
  • Click on the Review + Create button.
Why to create an Azure SQL database

Step-9: Finally, 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 a Microsoft Azure SQL Database Step By Step.

Query the SQL database in Azure

Once your database 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 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 on 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 in the Results pane.

You can also check out how To Create Tables In SQL Azure Database

How to create 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
create an azure 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 sql database on Azure 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" 
create azure sql database

Now after running the above script you can log in to the Azure portal and check if the SQL database has been created

setup azure sql database

Create Azure SQL database – Video Tutorial

FAQs

Why 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 in 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 have discussed how to create an Azure SQL Database using Azure Portal and PowerShell. Hope you have enjoyed this article !!!