Azure Documentation

Create an Azure SQL Database

This article guides you through the process of creating a new Azure SQL Database using various methods, including the Azure portal, Azure CLI, and PowerShell.

Overview

Azure SQL Database is a fully managed platform as a service (PaaS) database engine that handles most of the database management functions such as upgrading, patching, backups, and monitoring without user involvement. You can create an Azure SQL Database as part of an Azure SQL server or within an Azure SQL Managed Instance.

Note: Before creating an Azure SQL Database, you need to have an Azure subscription. If you don't have one, you can create a free account today.

Prerequisites

Methods for Creating an Azure SQL Database

You can create an Azure SQL Database using one of the following methods:

Azure portal
Azure CLI
Azure PowerShell

Using the Azure Portal

The Azure portal provides a user-friendly graphical interface for creating and managing Azure resources.

1

Sign in to the Azure portal.

2

In the Azure portal, search for and select SQL databases.

3

On the SQL databases page, select + Create.

4

On the Basics tab, fill out the following details:

  • Subscription: Select your Azure subscription.
  • Resource group: Select an existing resource group or create a new one.
  • Database name: Enter a unique name for your database.
  • Server: Select an existing logical server or click Create new to create a new server.
  • If creating a new server, enter a Server name, Server admin login, and Password.
  • Want to use SQL elastic pool?: Choose No unless you intend to use an elastic pool.
  • Compute + storage: Click Configure database to select the performance tier (DTU or vCore) and storage size.
  • Backup storage redundancy: Choose your desired backup redundancy option.
5

Click Review + create to validate your settings, then click Create to deploy the database.

Using the Azure CLI

The Azure Command-Line Interface (CLI) is a powerful tool for managing Azure resources from your terminal.

Ensure you have the Azure CLI installed and are logged in to your Azure account (`az login`).

Create a SQL database with a specific server name, resource group, and database name.
$ az sql db create \
    --resource-group myResourceGroup \
    --server myserver \
    --name mydatabase \
    --edition Basic \
    --family Gen5 \
    --capacity 2
Tip: You can create a new logical server if one doesn't exist by using the az sql server create command first.
Example of creating a new SQL server:
$ az sql server create \
    --name myserver \
    --resource-group myResourceGroup \
    --location eastus \
    --admin-user azureuser \
    --admin-password P@ssw0rd123

Using Azure PowerShell

Azure PowerShell provides cmdlets to manage Azure resources.

Ensure you have the Azure PowerShell module installed and are connected to your Azure account (`Connect-AzAccount`).

Create a SQL database using PowerShell.
PS C:\> New-AzSqlDatabase `
    -ResourceGroupName myResourceGroup `
    -ServerName myserver `
    -DatabaseName mydatabase `
    -Edition Standard `
    -RequestedServiceObjectiveName S0
Important: You need to specify the Edition and RequestedServiceObjectiveName (or other performance settings like MaxSizeBytes) when creating a database.

Post-creation

Once your Azure SQL Database is created, you can:

Note: Always review and configure security settings, especially firewall rules, to protect your database.