Edit

Create and configure a serverless database in Azure SQL Database

Applies to: Azure SQL Database

This article explains how to create a new serverless database, move an existing database to the serverless compute tier, and modify serverless configuration in Azure SQL Database.

Create a new serverless database

Creating a new database or moving an existing database into a serverless compute tier follows the same pattern as creating a new database in provisioned compute tier. The process involves the following two steps:

  1. Specify the service objective. The service objective prescribes the service tier, hardware configuration, and maximum vCores. For service objective options, see serverless resource limits.

  2. Optionally, specify the minimum vCores and auto-pause delay to change their default values. For more information, see Auto-pause and auto-resume.

The following examples create a new database in the serverless compute tier.

Use Azure portal

See Quickstart: Create a single database in Azure SQL Database using the Azure portal.

Use PowerShell

Create a new serverless General Purpose database with the following PowerShell example:

$resourceGroupName = "<resource group name>"
$serverName = "<logical SQL server name>"
$databaseName = "<new database name>"

$params = @{
    ResourceGroupName = $resourceGroupName
    ServerName = $serverName
    DatabaseName = $databaseName
    Edition = 'GeneralPurpose'
    ComputeModel = 'Serverless'
    ComputeGeneration = 'Gen5'
    MinVcore = 0.5
    MaxVcore = 2
    AutoPauseDelayInMinutes = 15
}
New-AzSqlDatabase @params

Use Azure CLI

Create a new serverless General Purpose database by using the following Azure CLI example:

$resourceGroupName = "<resource group name>"
$serverName = "<logical SQL server name>"
$databaseName = "<database name>"

az sql db create -g $resourceGroupName `
-s $serverName `
-n $databaseName `
-e GeneralPurpose `
--compute-model Serverless `
-f Gen5 `
--min-capacity 0.5 `
-c 2 `
--auto-pause-delay 15

Use Transact-SQL (T-SQL)

When you use T-SQL to create a new serverless database, the system applies default values for the minimum vCores and auto-pause delay. You can later change these values from the Azure portal or via API, including PowerShell, Azure CLI, and REST.

For details, see CREATE DATABASE.

Create a new General Purpose serverless database with the following T-SQL example:

CREATE DATABASE testdb
( EDITION = 'GeneralPurpose', SERVICE_OBJECTIVE = 'GP_S_Gen5_1' ) ;

Move a database between compute tiers or service tiers

You can move a database between the provisioned compute tier and serverless compute tier.

You can also move a serverless database from the General Purpose service tier to the Hyperscale service tier. For more information, see Convert an existing database to Hyperscale.

When you move a database between compute tiers, specify the compute model parameter as either Serverless or Provisioned when using PowerShell or Azure CLI. When using T-SQL, specify the SERVICE_OBJECTIVE. Review resource limits to identify the appropriate service objective.

The following examples move an existing database from provisioned compute to serverless.

Use PowerShell

Move a provisioned compute General Purpose database to the serverless compute tier by using the following PowerShell example:

$resourceGroupName = "<resource group name>"
$serverName = "<logical SQL server name>"
$databaseName = "<new database name>"

$params = @{
    ResourceGroupName = $resourceGroupName
    ServerName = $serverName
    DatabaseName = $databaseName
    Edition = 'GeneralPurpose'
    ComputeModel = 'Serverless'
    ComputeGeneration = 'Gen5'
    MinVcore = 1
    MaxVcore = 4
    AutoPauseDelayInMinutes = 1440
}
Set-AzSqlDatabase @params

Use Azure CLI

To move a provisioned compute General Purpose database to the serverless compute tier, use the following Azure CLI example:

$resourceGroupName = "<resource group name>"
$serverName = "<logical SQL server name>"
$databaseName = "<database name>"

az sql db update -g $resourceGroupName `
-s $serverName `
-n $databaseName `
--edition GeneralPurpose `
--compute-model Serverless `
--family Gen5 `
--min-capacity 1 `
--capacity 4 `
--auto-pause-delay 1440

Use Transact-SQL (T-SQL)

When you use T-SQL to move a database between compute tiers, the operation applies default values for the minimum vCores and auto-pause delay. You can change these values later from the Azure portal or via API, including PowerShell, Azure CLI, and REST. For more information, see ALTER DATABASE.

To move a provisioned compute General Purpose database to the serverless compute tier, use the following T-SQL example:

ALTER DATABASE testdb 
MODIFY ( SERVICE_OBJECTIVE = 'GP_S_Gen5_1') ;

Modify serverless configuration

Use PowerShell

Use Set-AzSqlDatabase to change the maximum or minimum vCores, and the auto-pause delay. Use the MaxVcore, MinVcore, and AutoPauseDelayInMinutes parameters. The Hyperscale tier doesn't currently support serverless auto-pausing, so the auto-pause delay parameter only applies to the General Purpose tier.

For example, to modify the MaxVcore, MinVcore, or AutoPauseDelayInMinutes

$resourceGroupName = "<resource group name>"
$serverName = "<logical SQL server name>"
$databaseName = "<new database name>"

$params = @{
    ResourceGroupName = $resourceGroupName
    ServerName = $serverName
    DatabaseName = $databaseName
    MinVcore = 1
    MaxVcore = 4
    AutoPauseDelayInMinutes = 1440
}
Set-AzSqlDatabase @params

Use Azure CLI

Use az sql db update to change the maximum or minimum vCores, and the auto-pause delay. Use the capacity, min-capacity, and auto-pause-delay parameters. The Hyperscale tier doesn't currently support serverless auto-pausing, so the auto-pause delay parameter only applies to the General Purpose tier.

For example, to modify the database to use a different minimum or maximum number of vCores, or to change the autopause delay:

$resourceGroupName = "<resource group name>"
$serverName = "<logical SQL server name>"
$databaseName = "<database name>"

az sql db update -g $resourceGroupName `
-s $serverName `
-n $databaseName `
--min-capacity 1 `
--capacity 4 `
--auto-pause-delay 1440