通过


你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Microsoft.Sql 服务器/自动优化

Bicep 资源定义

可以使用目标作部署服务器/automaticTuning 资源类型:

有关每个 API 版本中已更改属性的列表,请参阅 更改日志

资源格式

若要创建 Microsoft.Sql/servers/automaticTuning 资源,请将以下 Bicep 添加到模板。

resource symbolicname 'Microsoft.Sql/servers/automaticTuning@2024-11-01-preview' = {
  parent: resourceSymbolicName
  name: 'current'
}

属性值

Microsoft.Sql/servers/automaticTuning

Name Description Value
name 资源名称 “current”(必需)
父级 在 Bicep 中,可以为子资源指定父资源。 仅当子资源在父资源外部声明时,才需要添加此属性。

有关详细信息,请参阅 父资源外部的子资源
类型资源的符号名称:服务器

ARM 模板资源定义

可以使用目标作部署服务器/automaticTuning 资源类型:

有关每个 API 版本中已更改属性的列表,请参阅 更改日志

资源格式

若要创建 Microsoft.Sql/servers/automaticTuning 资源,请将以下 JSON 添加到模板。

{
  "type": "Microsoft.Sql/servers/automaticTuning",
  "apiVersion": "2024-11-01-preview",
  "name": "string"
}

属性值

Microsoft.Sql/servers/automaticTuning

Name Description Value
apiVersion API 版本 '2024-11-01-preview'
name 资源名称 “current”(必需)
类型 资源类型 'Microsoft.Sql/servers/automaticTuning'

用法示例

Terraform (AzAPI 提供程序)资源定义

可以使用目标作部署服务器/automaticTuning 资源类型:

有关每个 API 版本中已更改属性的列表,请参阅 更改日志

资源格式

若要创建 Microsoft.Sql/servers/automaticTuning 资源,请将以下 Terraform 添加到模板。

resource "azapi_resource" "symbolicname" {
  type = "Microsoft.Sql/servers/automaticTuning@2024-11-01-preview"
  name = "string"
  parent_id = "string"
}

属性值

Microsoft.Sql/servers/automaticTuning

Name Description Value
name 资源名称 “current”(必需)
parent_id 此资源的父资源的 ID。 类型资源的 ID:服务器
类型 资源类型 “Microsoft.Sql/servers/automaticTuning@2024-11-01-preview”

用法示例

Terraform 示例

部署 SQL Server 自动优化的基本示例。

terraform {
  required_providers {
    azapi = {
      source = "Azure/azapi"
    }
  }
}

provider "azapi" {
  skip_provider_registration = false
}

variable "resource_name" {
  type    = string
  default = "acctest0001"
}

variable "location" {
  type    = string
  default = "eastus"
}

variable "administrator_login_password" {
  type        = string
  description = "The administrator login password for the SQL server"
  sensitive   = true
}

resource "azapi_resource" "resourceGroup" {
  type     = "Microsoft.Resources/resourceGroups@2020-06-01"
  name     = var.resource_name
  location = var.location
}

resource "azapi_resource" "server" {
  type      = "Microsoft.Sql/servers@2021-11-01"
  parent_id = azapi_resource.resourceGroup.id
  name      = var.resource_name
  location  = var.location
  body = {
    properties = {
      administratorLogin            = "mradministrator"
      administratorLoginPassword    = var.administrator_login_password
      minimalTlsVersion             = "1.2"
      publicNetworkAccess           = "Enabled"
      restrictOutboundNetworkAccess = "Disabled"
      version                       = "12.0"
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

resource "azapi_resource_action" "automaticTuning" {
  resource_id = "${azapi_resource.server.id}/automaticTuning/current"
  type        = "Microsoft.Sql/servers/automaticTuning@2021-11-01"
  method      = "PATCH"
  body = {
    properties = {
      desiredState = "Auto"
      options = {
        forceLastGoodPlan = { desiredState = "Default" }
        createIndex       = { desiredState = "On" }
        dropIndex         = { desiredState = "Off" }
      }
    }
  }
}