How To Manage Azure SQL Database Using PowerShell

Introduction

In my previous blog, you saw how to create an Azure SQL database and to query the database on the Azure portal. Azure SQL Database is a relational Database-as-a-Service which provides high performance, reliable, and secure database used to build data-driven applications and websites. You can either use Azure cloud shell to run PowerShell from your browser or you can install it on your computer. In this blog, you will see how to perform the following tasks for the specific resource group and server using PowerShell.

  • Get SQL Databases
  • Create a new database
  • Set properties for a database
  • Remove an SQL database

SQL Server Details

Log in to the Azure Portal.

Click SQL Databases -> vijaiDB (which I have created in my previous article). Click Overview and you could see the server name and resource group which will be required for managing the SQL databases using PowerShell.

 

Open PowerShell from your browser

Log in to the Azure Portal.

Click Cloud Shell and then click PowerShell.

 

Create Storage and once the storage is created, it will take a few minutes for the Cloud Shell to open the PowerShell session.

 

Get-AzureRmSqlDatabase cmdlet will get the database for the specific server and resource group.

 

  1. PS Azure:\> Get-AzureRmSqlDatabase -ResourceGroupName "myResourceDB" -ServerName "mysqldbserver20171103"  

 

 

 

  1. PS Azure:\> Get-AzureRmSqlDatabase -ResourceGroupName "myResourceDB" -ServerName "mysqldbserver20171103" -DatabaseName "vijaiDB"  

 

 

New-AzureRmSqlDatabase cmdlet will create a new database on a specific server.

 

  1. PS Azure:\> New-AzureRmSqlDatabase -ResourceGroupName "myResourceDB" -ServerName "mysqldbserver20171103" -DatabaseName "vijaiDB001"  

 

 

Set-AzureRmSqlDatabase cmdlet will set the properties for existing SQL database.

 

  1. PS Azure:\> Set-AzureRmSqlDatabase -ResourceGroupName "myResourceDB" -ServerName "mysqldbserver20171103" -DatabaseName "vijaiDB001" -Edition Basic  

 

 

Remove-AzureRmSqlDatabase cmdlet will remove the database from the specific resource group and server.

 

  1. PS Azure:\> Remove-AzureRmSqlDatabase -ResourceGroupName "myResourceDB" -ServerName "mysqldbserver20171103" -DatabaseName "vijaiDB001"  

 

 

Result

Thus, in this blog, you saw how to manage Azure SQL Database using PowerShell.