หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
Use this Azure Resource Manager template (ARM template) to deploy a SQL Server on Azure Virtual Machine (VM).
An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax. In declarative syntax, you describe your intended deployment without writing the sequence of programming commands to create the deployment.
If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. The template will open in the Azure portal.
Prerequisites
The SQL Server VM ARM template requires the following:
- The latest version of the Azure CLI and/or PowerShell.
- A preconfigured resource group with a prepared virtual network and subnet.
- An Azure subscription. If you don't have one, create a free account before you begin.
Review the template
The template used in this quickstart is from Azure Quickstart Templates.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.39.26.7824",
"templateHash": "8885750212402280260"
}
},
"parameters": {
"virtualMachineName": {
"type": "string",
"defaultValue": "myVM",
"metadata": {
"description": "The name of the VM"
}
},
"virtualMachineSize": {
"type": "string",
"defaultValue": "Standard_D8s_v3",
"metadata": {
"description": "The virtual machine size."
}
},
"existingVirtualNetworkName": {
"type": "string",
"metadata": {
"description": "Specify the name of an existing VNet in the same resource group"
}
},
"existingVnetResourceGroup": {
"type": "string",
"defaultValue": "[resourceGroup().name]",
"metadata": {
"description": "Specify the resrouce group of the existing VNet"
}
},
"existingSubnetName": {
"type": "string",
"metadata": {
"description": "Specify the name of the Subnet Name"
}
},
"imageOffer": {
"type": "string",
"defaultValue": "sql2019-ws2022",
"allowedValues": [
"sql2025-ws2025",
"sql2022-ws2022",
"sql2019-ws2019",
"sql2017-ws2019",
"sql2019-ws2022",
"SQL2016SP1-WS2016",
"SQL2016SP2-WS2016",
"SQL2014SP3-WS2012R2",
"SQL2014SP2-WS2012R2"
],
"metadata": {
"description": "Windows Server and SQL Offer"
}
},
"sqlSku": {
"type": "string",
"defaultValue": "standard-gen2",
"allowedValues": [
"standard-gen2",
"enterprise-gen2",
"SQLDEV-gen2",
"web-gen2",
"enterprisedbengineonly-gen2"
],
"metadata": {
"description": "SQL Server Sku"
}
},
"adminUsername": {
"type": "string",
"metadata": {
"description": "The admin user name of the VM"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "The admin password of the VM"
}
},
"storageWorkloadType": {
"type": "string",
"defaultValue": "General",
"allowedValues": [
"General",
"OLTP",
"DW"
],
"metadata": {
"description": "SQL Server Workload Type"
}
},
"sqlDataDisksCount": {
"type": "int",
"defaultValue": 1,
"minValue": 1,
"maxValue": 8,
"metadata": {
"description": "Amount of data disks (1TB each) for SQL Data files"
}
},
"dataPath": {
"type": "string",
"defaultValue": "F:\\SQLData",
"metadata": {
"description": "Path for SQL Data files. Please choose drive letter from F to Z, and other drives from A to E are reserved for system"
}
},
"sqlLogDisksCount": {
"type": "int",
"defaultValue": 1,
"minValue": 1,
"maxValue": 8,
"metadata": {
"description": "Amount of data disks (1TB each) for SQL Log files"
}
},
"logPath": {
"type": "string",
"defaultValue": "G:\\SQLLog",
"metadata": {
"description": "Path for SQL Log files. Please choose drive letter from F to Z and different than the one used for SQL data. Drive letter from A to E are reserved for system"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"securityType": {
"type": "string",
"defaultValue": "TrustedLaunch",
"allowedValues": [
"Standard",
"TrustedLaunch"
],
"metadata": {
"description": "Security Type of the Virtual Machine."
}
}
},
"variables": {
"securityProfileJson": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "[parameters('securityType')]"
},
"networkInterfaceName": "[format('{0}-nic', parameters('virtualMachineName'))]",
"networkSecurityGroupName": "[format('{0}-nsg', parameters('virtualMachineName'))]",
"networkSecurityGroupRules": [
{
"name": "RDP",
"properties": {
"priority": 300,
"protocol": "Tcp",
"access": "Allow",
"direction": "Inbound",
"sourceAddressPrefix": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "*",
"destinationPortRange": "3389"
}
}
],
"publicIpAddressName": "[format('{0}-publicip-{1}', parameters('virtualMachineName'), uniqueString(parameters('virtualMachineName')))]",
"publicIpAddressType": "Static",
"publicIpAddressSku": "Standard",
"diskConfigurationType": "NEW",
"nsgId": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]",
"subnetRef": "[resourceId(parameters('existingVnetResourceGroup'), 'Microsoft.Network/virtualNetWorks/subnets', parameters('existingVirtualNetworkName'), parameters('existingSubnetName'))]",
"dataDisksLuns": "[range(0, parameters('sqlDataDisksCount'))]",
"logDisksLuns": "[range(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount'))]",
"dataDisks": {
"createOption": "Empty",
"caching": "ReadOnly",
"writeAcceleratorEnabled": false,
"storageAccountType": "Premium_LRS",
"diskSizeGB": 1023
},
"tempDbPath": "D:\\SQLTemp",
"extensionName": "GuestAttestation",
"extensionPublisher": "Microsoft.Azure.Security.WindowsAttestation",
"extensionVersion": "1.0",
"maaTenantName": "GuestAttestation"
},
"resources": [
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2022-01-01",
"name": "[variables('publicIpAddressName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[variables('publicIpAddressSku')]"
},
"properties": {
"publicIPAllocationMethod": "[variables('publicIpAddressType')]"
}
},
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2022-01-01",
"name": "[variables('networkSecurityGroupName')]",
"location": "[parameters('location')]",
"properties": {
"securityRules": "[variables('networkSecurityGroupRules')]"
}
},
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2022-01-01",
"name": "[variables('networkInterfaceName')]",
"location": "[parameters('location')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIpAddressName'))]"
}
}
}
],
"enableAcceleratedNetworking": true,
"networkSecurityGroup": {
"id": "[variables('nsgId')]"
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]",
"[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIpAddressName'))]"
]
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2022-03-01",
"name": "[parameters('virtualMachineName')]",
"location": "[parameters('location')]",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"copy": [
{
"name": "dataDisks",
"count": "[length(range(0, length(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount'))))))]",
"input": {
"lun": "[range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))[range(0, length(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))))[copyIndex('dataDisks')]]]",
"createOption": "[variables('dataDisks').createOption]",
"caching": "[if(greaterOrEquals(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))[range(0, length(range(0, add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))))[copyIndex('dataDisks')]], parameters('sqlDataDisksCount')), 'None', variables('dataDisks').caching)]",
"writeAcceleratorEnabled": "[variables('dataDisks').writeAcceleratorEnabled]",
"diskSizeGB": "[variables('dataDisks').diskSizeGB]",
"managedDisk": {
"storageAccountType": "[variables('dataDisks').storageAccountType]"
}
}
}
],
"osDisk": {
"createOption": "FromImage",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"imageReference": {
"publisher": "MicrosoftSQLServer",
"offer": "[parameters('imageOffer')]",
"sku": "[parameters('sqlSku')]",
"version": "latest"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"windowsConfiguration": {
"enableAutomaticUpdates": true,
"provisionVMAgent": true
}
},
"securityProfile": "[if(equals(parameters('securityType'), 'TrustedLaunch'), variables('securityProfileJson'), null())]"
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
]
},
{
"condition": "[and(equals(parameters('securityType'), 'TrustedLaunch'), and(equals(variables('securityProfileJson').uefiSettings.secureBootEnabled, true()), equals(variables('securityProfileJson').uefiSettings.vTpmEnabled, true())))]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2022-03-01",
"name": "[format('{0}/{1}', parameters('virtualMachineName'), variables('extensionName'))]",
"location": "[parameters('location')]",
"properties": {
"publisher": "[variables('extensionPublisher')]",
"type": "[variables('extensionName')]",
"typeHandlerVersion": "[variables('extensionVersion')]",
"autoUpgradeMinorVersion": true,
"enableAutomaticUpgrade": true,
"settings": {
"AttestationConfig": {
"MaaSettings": {
"maaEndpoint": "",
"maaTenantName": "[variables('maaTenantName')]"
},
"AscSettings": {
"ascReportingEndpoint": "",
"ascReportingFrequency": ""
},
"useCustomToken": "false",
"disableAlerts": "false"
}
}
},
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]"
]
},
{
"type": "Microsoft.SqlVirtualMachine/sqlVirtualMachines",
"apiVersion": "2022-07-01-preview",
"name": "[parameters('virtualMachineName')]",
"location": "[parameters('location')]",
"properties": {
"virtualMachineResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
"sqlManagement": "Full",
"sqlServerLicenseType": "PAYG",
"storageConfigurationSettings": {
"diskConfigurationType": "[variables('diskConfigurationType')]",
"storageWorkloadType": "[parameters('storageWorkloadType')]",
"sqlDataSettings": {
"luns": "[variables('dataDisksLuns')]",
"defaultFilePath": "[parameters('dataPath')]"
},
"sqlLogSettings": {
"luns": "[variables('logDisksLuns')]",
"defaultFilePath": "[parameters('logPath')]"
},
"sqlTempDbSettings": {
"defaultFilePath": "[variables('tempDbPath')]"
}
}
},
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]"
]
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}
Five Azure resources are defined in the template:
- Microsoft.Network/publicIpAddresses: Creates a public IP address.
- Microsoft.Network/networkSecurityGroups: Creates a network security group.
- Microsoft.Network/networkInterfaces: Configures the network interface.
- Microsoft.Compute/virtualMachines: Creates a virtual machine in Azure.
- Microsoft.SqlVirtualMachine/sqlVirtualMachines: Registers the virtual machine with the SQL IaaS Agent extension.
More SQL Server on Azure VM templates can be found in the quickstart template gallery.
Deploy the template
Select the following image to sign in to Azure and open a template. The template creates a virtual machine with the intended SQL Server version installed on it and registers the VM with the SQL IaaS Agent extension.
Complete the deployment form fields in order:
- Subscription – Select an Azure subscription.
- Resource group – Select the prepared resource group for the SQL Server VM.
- Region – Select a region (for example, Central US).
- Virtual machine name – Enter a name for the SQL Server VM.
- Virtual machine size – Choose an appropriate VM size.
- Virtual network (VNet) – Specify the existing virtual network and subnet.
- SQL Server configuration – Select the image offer, SQL SKU, and storage workload settings.
- Administrator credentials – Enter the admin username and password.
Review the deployment parameters:
Parameter Type / Default Allowed values / Constraints Description Subscription Required Existing Azure subscription Azure subscription used for deployment. Resource group Required Existing resource group Prepared resource group for the SQL Server VM. Region Default: resourceGroup().location Azure regions Azure region for the VM (for example, Central US). virtualMachineName String 1–15 characters Name of the SQL Server virtual machine. virtualMachineSize String Azure VM sizes Size of the virtual machine. existingVirtualNetworkName String Existing virtual network (VNet) Name of the prepared virtual network (VNet). existingVnetResourceGroup String Existing resource group Resource group containing the virtual network. existingSubnetName String Existing subnet Name of the prepared subnet. imageOffer String SQL Server and Windows Server images SQL Server and Windows Server image offer. sqlSku String Developer, Express, Standard, Enterprise SQL Server edition SKU. adminUsername String — Administrator username for the VM. adminPassword Secure string Complexity enforced Administrator password for the VM. storageWorkloadType String OLTP, DW, General Storage workload type (OLTP = Online Transaction Processing, DW = Data Warehouse). sqlDataDisksCount Int Min/Max per SKU Number of disks used for SQL Server data files. dataPath String Valid path Path for SQL Server data files. sqlLogDisksCount Int Min/Max per SKU Number of disks used for SQL Server log files. logPath String Valid path Path for SQL Server log files. location Default: resourceGroup().location Azure regions Location for all resources. Select Review + create, then select Create.
Verify deployment success:
- Portal: Confirm the deployment status shows Succeeded.
- Azure CLI:
az resource show --resource-group <resource-group> --name <vm-name> --resource-type Microsoft.Compute/virtualMachines
The Azure portal is used to deploy the template. In addition to the Azure portal, you can also use Azure PowerShell, the Azure CLI, and the REST API. To learn about other deployment methods, see Deploy templates.
Review deployed resources
You can use the Azure CLI to check deployed resources.
echo "Enter the resource group where your SQL Server VM exists:" &&
read resourcegroupName &&
az resource list --resource-group $resourcegroupName
Clean up resources
When no longer needed, delete the resource group by using Azure CLI or Azure PowerShell:
echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."
Next steps
For a step-by-step tutorial that guides you through the process of creating a template, see:
For other ways to deploy a SQL Server VM, see:
To learn more, see an overview of SQL Server on Azure VMs.