Azure Hands-on Labs - Creating Azure SQL Databases using PowerShell
Azure Learning Path for Cloud and DevOps Engineers
📝Introduction
This post demonstrates this hands-on lab, where we walk through using Azure PowerShell to create a SQL Database. This beginner-level hands-on lab covers several concepts, including the following.
Creating variables
to store key parameters. Identifying the proper cmdlets
to create an Azure SQL Server and Azure SQL Database. Creating the Azure SQL Server and Database using the correct parameters.
This hands-on lab uses the Azure Cloud Shell, so there's no need to install any software.
📝Log in to the Azure Management Console
Using your credentials, make sure you're using the right Region. In my case, I am using west-us
.
📌Note: You can also use the VSCode tool or from your local PowerShell to connect to Azure PowerShell
More information on how to set up it is on the link.
📝Prerequisites:
Update to PowerShell 5.1, if needed.
Install .NET Framework 4.7.2 or later.
VisualCode
Web Browser (Chrome, Edge)
📝Setting an Azure Storage Account to Load Powershell
- Click the Cloud Shell icon
(>_)
at the top of the page.
- Click PowerShell.
- Click Show Advanced Settings. Use the combo box under Cloud Shell region to select the Region. Under Resource group and Storage account(It's a globally unique name), enter a name for both. In the box under File Share, enter a name. Click Create Storage (if you don't have any yet).
📝Creating Azure SQL Databases Using PowerShell
Identify your current resource group.
Get-AzResourceGroup #Copy the value for the ResourceGroupName parameter to the clipboard. #This will be referred to as RESOURCE_GROUP_NAME for the rest of this guide.
Set variables to Resource Group, Location and Server Name
$resourcegroup = '<name_resource_group>' $location = '<region_name>' $name = '<server_name>'
Create the Azure SQL Server
New-AzSqlServer ` -ResourceGroupName $resource ` -Location $location ` -ServerName $name ` -ServerVersion '12.0' ` -SqlAdministratorCredentials (Get-Credential)
Enter a user name when prompted. Provide a password when prompted.
📌Note - If you receive an error that the name of server already exists, redefine $name as a unique name, and then rerun the first command in this task.
You can also check on the Azure Management Console the resources created.
Create the SQL Database
New-AzSqlDatabase -ResourceGroupName $resource -ServerName $name -DatabaseName 'Database01'
You can also check on the Azure Management Console the resources created.
📌Note - At the end of each hands-on Lab, always clean up all the resources previously created to avoid being charged.
Congratulations — you have completed this hands-on lab covering the basics of Azure Creating a SQL Database Account using the PowerShell tool.
Thank you for reading. I hope you understood and learned something helpful from my blog.
Please follow me on CloudDevOpsToLearn and LinkedIn franciscojblsouza