| title | PowerShell: Create a Single Database | ||
|---|---|---|---|
| description | Use an Azure PowerShell example script to create a single database in Azure SQL Database. | ||
| author | WilliamDAssafMSFT | ||
| ms.author | wiassaf | ||
| ms.reviewer | wiassaf, mathoma | ||
| ms.date | 06/10/2025 | ||
| ms.service | azure-sql-database | ||
| ms.subservice | deployment-configuration | ||
| ms.topic | sample | ||
| ms.custom |
|
||
| ms.devlang | powershell |
[!INCLUDEappliesto-sqldb]
This Azure PowerShell script example creates a single database in Azure SQL Database and configures a server-level firewall rule. After the script has been successfully run, the database can be accessed from all Azure services and the allowed IP address range.
[!INCLUDE quickstarts-free-trial-note] [!INCLUDE updated-for-az] [!INCLUDE cloud-shell-try-it.md]
If you choose to install and use PowerShell locally, this tutorial requires Az PowerShell 1.4.0 or later. If you need to upgrade, see Install Azure PowerShell module. If you are running PowerShell locally, you also need to run Connect-AzAccount to create a connection with Azure.
[!code-powershell-interactivemain]
Use the following command to remove the resource group and all resources associated with it.
Remove-AzResourceGroup -ResourceGroupName $resourcegroupnameThis script uses the following commands. Each command in the table links to command-specific documentation.
| Command | Notes |
|---|---|
| New-AzResourceGroup | Creates a resource group in which all resources are stored. |
| New-AzSqlServer | Creates a server that hosts databases and elastic pools. |
| New-AzSqlServerFirewallRule | Creates a server-level firewall rule for a server. |
| New-AzSqlDatabase | Creates a database in a server. |
| Remove-AzResourceGroup | Deletes a resource group including all nested resources. |
For more information on the benefits of using a user-assigned managed identity for the server identity in Azure SQL Database, see Managed identities in Microsoft Entra for Azure SQL.
To configure the system-assigned managed identity (SMI) or user-assigned managed identity or identities (UMI) of an Azure SQL Database, see Get or set a managed identity for a logical server or managed instance.