快速入门:使用 ARM 模板在 Azure SQL 数据库中创建单一数据库Quickstart: Create a single database in Azure SQL Database using an ARM template

在 Azure SQL 数据库中创建数据库时,创建单一数据库是最快速且最简单的选项。Creating a single database is the quickest and simplest option for creating a database in Azure SQL Database. 本快速入门介绍如何使用 Azure 资源管理器模板(ARM 模板)创建单一数据库。This quickstart shows you how to create a single database using an Azure Resource Manager template (ARM template).

ARM 模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. 该模板使用声明性语法,使你可以声明要部署的内容,而不需要编写一系列编程命令来进行创建。The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it.

如果你的环境满足先决条件,并且你熟悉如何使用 ARM 模板,请选择“部署到 Azure”按钮。If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. Azure 门户中会打开模板。The template will open in the Azure portal.

部署到 AzureDeploy to Azure

先决条件Prerequisites

如果没有 Azure 订阅,请创建一个试用版订阅If you don't have an Azure subscription, create a Trial Subscription.

查看模板Review the template

单一数据库有一组通过两个购买模型中的一个定义的计算、内存和存储资源。A single database has a defined set of compute, memory, IO, and storage resources using one of two purchasing models. 创建单一数据库时,还需要定义一个服务器来管理它并将它放置在指定区域的 Azure 资源组中。When you create a single database, you also define a server to manage it and place it within Azure resource group in a specified region.

本快速入门中使用的模板来自 Azure 快速启动模板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",
  "parameters": {
    "serverName": {
      "type": "string",
      "defaultValue": "[uniqueString('sql', resourceGroup().id)]",
      "metadata": {
        "description": "The name of the SQL logical server."
      }
    },
    "sqlDBName": {
      "type": "string",
      "defaultValue": "SampleDB",
      "metadata": {
        "description": "The name of the SQL Database."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "administratorLogin": {
      "type": "string",
      "metadata": {
        "description": "The administrator username of the SQL logical server."
      }
    },
    "administratorLoginPassword": {
      "type": "securestring",
      "metadata": {
        "description": "The administrator password of the SQL logical server."
      }
    }
  },
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.Sql/servers",
      "apiVersion": "2019-06-01-preview",
      "name": "[parameters('serverName')]",
      "location": "[parameters('location')]",
      "properties": {
        "administratorLogin": "[parameters('administratorLogin')]",
        "administratorLoginPassword": "[parameters('administratorLoginPassword')]"
      },
      "resources": [
        {
          "type": "databases",
          "apiVersion": "2019-06-01-preview",
          "name": "[parameters('sqlDBName')]",
          "sku": {
            "name": "Standard",
            "tier": "Standard"
          },
          "location": "[parameters('location')]",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', concat(parameters('serverName')))]"
          ]
        }
      ]
    }
  ]
}

该模板中定义了以下资源:These resources are defined in the template:

可以在 Azure 快速入门模板中找到更多 Azure SQL 数据库模板示例。More Azure SQL Database template samples can be found in Azure Quickstart Templates.

部署模板Deploy the template

$projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
$location = Read-Host -Prompt "Enter an Azure location (i.e. chinaeast2)"
$adminUser = Read-Host -Prompt "Enter the SQL server administrator username"
$adminPassword = Read-Host -Prompt "Enter the SQl server administrator password" -AsSecureString

$resourceGroupName = "${projectName}rg"

New-AzResourceGroup -Name $resourceGroupName -Location $location
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-sql-database/azuredeploy.json" -administratorLogin $adminUser -administratorLoginPassword $adminPassword

Read-Host -Prompt "Press [ENTER] to continue ..."

验证部署Validate the deployment

若要查询数据库,请参阅查询数据库To query the database, see Query the database.

清理资源Clean up resources

如果希望转到后续步骤,请保留此资源组、服务器和单一数据库。Keep this resource group, server, and single database if you want to go to the Next steps. 后续步骤展示了如何使用各种方法连接和查询数据库。The next steps show you how to connect and query your database using different methods.

若要删除资源组,请执行以下操作:To delete the resource group:

$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name"
Remove-AzResourceGroup -Name $resourceGroupName

后续步骤Next steps