Friday, August 2, 2019

Create and query an Azure SQL data warehouse with Azure PowerShell

Quickly create an Azure SQL data warehouse using Azure PowerShell.
If you don't have an Azure subscription, create a free account before you begin.
 Note
Creating a SQL Data Warehouse may result in a new billable service. For more information, see SQL Data Warehouse pricing.
 Note
This article has been updated to use the new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 

Sign in to Azure

Sign in to your Azure subscription using the Connect-AzAccount command and follow the on-screen directions.
PowerShellop
Connect-AzAccount
To see which subscription you're using, run Get-AzSubscription.
PowerShell
Get-AzSubscription
If you need to use a different subscription than the default, run Set-AzContext.
PowerShell
Set-AzContext -SubscriptionName "MySubscription"

Create variables

Define variables for use in the scripts in this quickstart.
PowerShell
# The data center and resource name for your resources
$resourcegroupname = "myResourceGroup"
$location = "WestEurope"
# The logical server name: Use a random value or replace with your own value (don't capitalize)
$servername = "server-$(Get-Random)"
# Set an admin name and password for your database
# The sign-in information for the server
$adminlogin = "ServerAdmin"
$password = "ChangeYourAdminPassword1"
# The ip address range that you want to allow to access your server - change as appropriate
$startip = "0.0.0.0"
$endip = "0.0.0.0"
# The database name
$databasename = "mySampleDataWarehosue"

Create a resource group

Create an Azure resource group using the New-AzResourceGroup command. A resource group is a logical container into which Azure resources are deployed and managed as a group. The following example creates a resource group named myResourceGroup in the westeurope location.
PowerShell
New-AzResourceGroup -Name $resourcegroupname -Location $location

Create a logical server

Create an Azure SQL logical server using the New-AzSqlServer command. A logical server contains a group of databases managed as a group. The following example creates a randomly named server in your resource group with an admin user named ServerAdmin and a password of ChangeYourAdminPassword1. Replace these pre-defined values as desired.
PowerShell
New-AzSqlServer -ResourceGroupName $resourcegroupname `
    -ServerName $servername `
    -Location $location `
    -SqlAdministratorCredentials $(New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminlogin, $(ConvertTo-SecureString -String $password -AsPlainText -Force))

Configure a server firewall rule

Create an Azure SQL server-level firewall rule using the New-AzSqlServerFirewallRule command. A server-level firewall rule allows an external application, such as SQL Server Management Studio or the SQLCMD utility to connect to a SQL data warehouse through the SQL Data Warehouse service firewall. In the following example, the firewall is only opened for other Azure resources. To enable external connectivity, change the IP address to an appropriate address for your environment. To open all IP addresses, use 0.0.0.0 as the starting IP address and 255.255.255.255 as the ending address.
PowerShell
New-AzSqlServerFirewallRule -ResourceGroupName $resourcegroupname `
    -ServerName $servername `
    -FirewallRuleName "AllowSome" -StartIpAddress $startip -EndIpAddress $endip
 Note
SQL Database and SQL Data Warehouse communicate over port 1433. If you're trying to connect from within a corporate network, outbound traffic over port 1433 may not be allowed by your network's firewall. If so, you won't be able to connect to your Azure SQL server unless your IT department opens port 1433.

Create a data warehouse

This example creates a data warehouse using the previously defined variables. It specifies the service objective as DW100c, which is a lower-cost starting point for your data warehouse.
Powershell:-
New-AzSqlDatabase `
    -ResourceGroupName $resourcegroupname `
    -ServerName $servername `
    -DatabaseName $databasename `
    -Edition "DataWarehouse" `
    -RequestedServiceObjectiveName "DW100c" `
    -CollationName "SQL_Latin1_General_CP1_CI_AS" `
    -MaxSizeBytes 10995116277760
Required Parameters are:-
  • RequestedServiceObjectiveName: The amount of data warehouse units you're requesting. Increasing this amount increases compute cost. For a list of supported values, see memory and concurrency limits.
  • DatabaseName: The name of the SQL Data Warehouse that you're creating.
  • ServerName: The name of the server that you're using for creation.
  • ResourceGroupName: Resource group you're using. To find available resource groups in your subscription use Get-AzureResource.
  • Edition: Must be "DataWarehouse" to create a SQL Data Warehouse.
Optional Parameters are:
  • CollationName: The default collation if not specified is SQL_Latin1_General_CP1_CI_AS. Collation can't be changed on a database.
  • MaxSizeBytes: The default max size of a database is 240TB. The max size limits rowstore data. There is unlimited storage for columnar data.
For more information on the parameter options, see New-AzSqlDatabase.

Clean up resources

Other quickstart tutorials in this collection build upon this quickstart.
 Tip
If you plan to continue on to work with later quickstart tutorials, don't clean up the resources created in this quickstart. If you don't plan to continue, use the following steps to delete all resources created by this quickstart in the Azure portal.
PowerShell
Remove-AzResourceGroup -ResourceGroupName $resourcegroupname

No comments:

Post a Comment

Lab 09: Publish and subscribe to Event Grid events

  Microsoft Azure user interface Given the dynamic nature of Microsoft cloud tools, you might experience Azure UI changes that occur after t...