Skip to content

Latest commit

 

History

History
56 lines (41 loc) · 2.76 KB

File metadata and controls

56 lines (41 loc) · 2.76 KB
title PowerShell: Create a single database
description Use an Azure PowerShell example script to create a single database in Azure SQL Database.
services sql-database
ms.service sql-database
ms.subservice single-database
ms.custom sqldbrb=1
ms.devlang PowerShell
ms.topic sample
author stevestein
ms.author sstein
ms.reviewer
ms.date 03/12/2019

Use PowerShell to create a single database and configure a server-level firewall rule

[!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 configured IP address.

[!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.

Sample script

[!code-powershell-interactivemain]

Clean up deployment

Use the following command to remove the resource group and all resources associated with it.

Remove-AzResourceGroup -ResourceGroupName $resourcegroupname

Script explanation

This 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.

Next steps

For more information on Azure PowerShell, see Azure PowerShell documentation.

Additional SQL Database PowerShell script samples can be found in the Azure SQL Database PowerShell scripts.