Create a Windows Azure SQL Database with PowerShell



  • Before getting started, make sure you have the latest Azure PowerShell installed. Once installed, start an Azure PowerShell session from your machine. First, you'll need to log in and authenticate to Windows Azure.
Add-AzureRmAccount
click below button to copy the code. By azure tutorial team
  • You'll receive a dialog box asking for your Azure credentials. Enter those, then hit sign in. Next, you'll need to identify which subscription you want to add this new SQL Database to. In PowerShell, it's easier to identify your subscription by Globally Unique Identifier (GUID), rather than by name.
  • To find your Subscription GUID, go to https://portal.azure.com and hit the subscriptions tile from the portal landing page.

Learn Azure - Azure tutorial - Subscription Module - Azure examples - Azure programs

The landing page blade will be replaced with your Subscriptions blade. From here, you can see all the subscriptions you have access to in your current Windows Azure Active Directory context. Keep a copy of these GUIDs ready for future PowerShell Scripts. Now that you have your subscription's GUID, you can set the scope of your PowerShell session to that subscription.

Set-AzureRmContext -SubscriptionId '<your subscription's GUID>'
click below button to copy the code. By azure tutorial team
  • Now, if you do not have an existing resource group to add this new SQL Database to, you will need to create one. At a minimum, your resource group needs a name and a location. Locations are the different datacenters that can host your Azure resources.
  • To get a list of Azure data centers capable of hosting your SQL Database run the following command.
(Get-AzureRmLocation | Where-Object { $_.Providers -eq "Microsoft.Sql" }).Location
click below button to copy the code. By azure tutorial team
  • Notice all locations are in lower case. Now, to create a new resource group use the following command.
New-AzureRmResourceGroup 
     -Name '<new_resource_group>' `
     -Location '<data_center>'
click below button to copy the code. By azure tutorial team
  • Next, you need a server to host your SQL Database. If you do not have a server you wish to use already, create one now. Servers require a resource group name, server name, and location.
New-AzureRmSqlServer `
     -Location '<data_center>' `
     -ResourceGroupName '<new_resource_group>' `
     -ServerName '<sql_server_name>'
click below button to copy the code. By azure tutorial team
  • You'll be prompted for an administrative username and password. This will be your new SQL Server's "sa" or system administrator account.
  • Now that you have a resource group and SQL server name, you're ready to create the database itself. The last two selections to make are edition and service tier.

For edition, you can choose Default, None, Premium, Basic, Standard, DataWarehouse, or Free. For service tier, you have many more choices. For beginners, stick with those you can see pricing for on the Azure price calculator. For more advanced users, check out the PowerShell cmdletGet-AzureRmSqlServerServiceObjective.

The following command will create your SQL Database.

New-AzureRmSqlDatabase `
     -DatabaseName '<database_name>' `
     -Edition 'basic' `
     -ResourceGroupName '<new_resource_group>' `
     -RequestedServiceObjectiveName 'basic' `
     -ServerName '<sql_server_name>' 
click below button to copy the code. By azure tutorial team

Related Searches to Create a Windows Azure SQL Database with PowerShell