| title | Azure Resource Manager: Create a single database | |||
|---|---|---|---|---|
| description | Create a single database in Azure SQL Database using an Azure Resource Manager template. | |||
| author | WilliamDAssafMSFT | |||
| ms.author | wiassaf | |||
| ms.reviewer | mathoma | |||
| ms.date | 09/17/2024 | |||
| ms.service | azure-sql-database | |||
| ms.subservice | deployment-configuration | |||
| ms.topic | quickstart | |||
| ms.custom |
|
[!INCLUDE appliesto-sqldb]
Creating a single database is the quickest and simplest option for creating a database in Azure SQL Database. This quickstart shows you how to create a single database using an Azure Resource Manager template (ARM template).
[!INCLUDE About Azure Resource Manager]
If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. The template will open in the Azure portal.
If you don't have an Azure subscription, create a free account.
To create databases via Transact-SQL: CREATE DATABASE permissions are necessary. To create a database a login must be either the server admin login (created when the Azure SQL Database logical server was provisioned), the Microsoft Entra admin of the server, a member of the dbmanager database role in master. For more information, see CREATE DATABASE.
To create databases via the Azure portal, PowerShell, Azure CLI, or REST API: Azure RBAC permissions are needed, specifically the Contributor, SQL DB Contributor, or SQL Server Contributor Azure RBAC role. For more information, see Azure RBAC built-in roles.
A single database has a defined set of compute, memory, IO, and storage resources using one of two purchasing models. When you create a single database, you also define a server to manage it and place it within Azure resource group in a specified region.
The template used in this quickstart is from Azure Quickstart Templates.
:::code language="json" source="~/../quickstart-templates/quickstarts/microsoft.sql/sql-database/azuredeploy.json":::
These resources are defined in the template:
More Azure SQL Database template samples can be found in Azure Quickstart Templates.
Select Try it from the following PowerShell code block to open Azure Cloud Shell.
$projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
$location = Read-Host -Prompt "Enter an Azure location (i.e. centralus)"
$adminUser = Read-Host -Prompt "Enter the SQL server administrator username"
$adminPassword = Read-Host -Prompt "Enter the SQL Server administrator password" -AsSecureString
$resourceGroupName = "${projectName}rg"
New-AzResourceGroup -Name $resourceGroupName -Location $location
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.sql/sql-database/azuredeploy.json" -administratorLogin $adminUser -administratorLoginPassword $adminPassword
Read-Host -Prompt "Press [ENTER] to continue ..."
To query the database, see Query the database.
Keep this resource group, server, and single database if you want. You can now connect and query your database using different methods.
- Create a server-level firewall rule to connect to the single database from on-premises or remote tools. For more information, see Create a server-level firewall rule.
- After you create a server-level firewall rule, connect and query your database using several different tools and languages:
If you want to delete the resource group:
$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name"
Remove-AzResourceGroup -Name $resourceGroupName
- To create a single database using the Azure CLI, see Azure CLI samples.
- To create a single database using Azure PowerShell, see Azure PowerShell samples.
- To learn how to create ARM templates, see Create your first template.