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.
- 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.
- 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.
- Notice all locations are in lower case. Now, to create a new resource group use the following command.
- 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.
- 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.