Microsoft。SQL 伺服器/資料庫

Bicep 資源定義

伺服器/資料庫資源類型可以使用目標作業來部署:

如需每個 API 版本中已變更屬性的清單,請參閱 變更記錄檔

資源格式

創造一個 Microsoft。Sql/servers/databases 資源,請在你的範本中加入以下 Bicep。

resource symbolicname 'Microsoft.Sql/servers/databases@2025-02-01-preview' = {
  parent: resourceSymbolicName
  identity: {
    type: 'string'
    userAssignedIdentities: {
      {customized property}: {}
    }
  }
  location: 'string'
  name: 'string'
  properties: {
    autoPauseDelay: int
    availabilityZone: 'string'
    catalogCollation: 'string'
    collation: 'string'
    createMode: 'string'
    elasticPoolId: 'string'
    encryptionProtector: 'string'
    encryptionProtectorAutoRotation: bool
    federatedClientId: 'string'
    freeLimitExhaustionBehavior: 'string'
    highAvailabilityReplicaCount: int
    isLedgerOn: bool
    keys: {
      {customized property}: {}
    }
    licenseType: 'string'
    longTermRetentionBackupResourceId: 'string'
    maintenanceConfigurationId: 'string'
    manualCutover: bool
    maxSizeBytes: int
    minCapacity: int
    performCutover: bool
    preferredEnclaveType: 'string'
    readScale: 'string'
    recoverableDatabaseId: 'string'
    recoveryServicesRecoveryPointId: 'string'
    requestedBackupStorageRedundancy: 'string'
    restorableDroppedDatabaseId: 'string'
    restorePointInTime: 'string'
    sampleName: 'string'
    secondaryType: 'string'
    sourceDatabaseDeletionDate: 'string'
    sourceDatabaseId: 'string'
    sourceResourceId: 'string'
    useFreeLimit: bool
    zoneRedundant: bool
  }
  sku: {
    capacity: int
    family: 'string'
    name: 'string'
    size: 'string'
    tier: 'string'
  }
  tags: {
    {customized property}: 'string'
  }
}

屬性值

Microsoft。Sql/伺服器/資料庫

Name Description Value
身分識別 資料庫的 Azure Active Directory 身份。 DatabaseIdentity
位置 資源所在的地理位置 字串 (必要)
name 資源名稱 字串 (必要)
父代 在 Bicep 中,你可以指定子資源的父資源。 只有在父資源外部宣告子資源時,才需要新增這個屬性。

如需詳細資訊,請參閱 父資源外部的子資源
類型的資源符號名稱:伺服器
properties 資源屬性。 DatabaseProperties
sku 資料庫 SKU。

SKU 清單可能會因區域和支援供應項目而異。 要確定在Azure區域內訂閱可用的 SKU(包括 SKU 名稱、階級/版本、家族及容量),請使用 Capabilities_ListByLocation REST API 或以下指令之一:

azurecli<br />az sql db list-editions -l &lt;location&gt; -o table<br />

powershell<br />Get-AzSqlServerServiceObjective -Location &lt;location&gt;<br />
Sku
tags 資源標籤 標記名稱和值的字典。 請參閱範本中的 標籤

DatabaseIdentity

Name Description Value
型別 識別類型 'None'
'UserAssigned'
userAssignedIdentities 要使用的使用者指派身分識別的資源標識碼 DatabaseIdentityUserAssignedIdentities

DatabaseIdentityUserAssignedIdentities

Name Description Value

DatabaseKey

Name Description Value

DatabaseProperties

Name Description Value
autoPauseDelay 在幾分鐘后自動暫停資料庫的時間。 -1 值表示已停用自動暫停 int
availabilityZone 指定資料庫釘選到的可用性區域。 '1'
'2'
'3'
'NoPreference'
catalogCollation 元資料目錄的定序。 'DATABASE_DEFAULT'
'SQL_Latin1_General_CP1_CI_AS'
定序 資料庫的定序。 字串
createMode 指定資料庫建立模式。

默認值:定期建立資料庫。

複製:建立資料庫做為現有資料庫的複本。 sourceDatabaseId 必須指定為源資料庫的資源標識碼。

次要:建立資料庫做為現有資料庫的次要複本。 sourceDatabaseId 必須指定為現有主資料庫的資源標識碼。

PointInTimeRestore:藉由還原現有資料庫的時間點備份來建立資料庫。 sourceDatabaseId 必須指定為現有資料庫的資源標識符,而且必須指定 restorePointInTime。

復原:藉由還原異地復寫備份來建立資料庫。 sourceDatabaseId 必須指定為要還原的可復原資料庫資源標識符。

還原:藉由還原已刪除資料庫的備份來建立資料庫。 必須指定sourceDatabaseId。 如果 sourceDatabaseId 是資料庫的原始資源識別碼,則必須指定 sourceDatabaseDeletionDate。 否則,sourceDatabaseId 必須是可還原的卸除資料庫資源標識符,而且會忽略 sourceDatabaseDeletionDate。 restorePointInTime 也可以指定為從先前的時間點還原。

RestoreLongTermRetentionBackup:從長期保留保存庫還原來建立資料庫。 recoveryServicesRecoveryPointResourceId 必須指定為恢復點資源標識符。

DataWarehouse 版本不支援 Copy、Secondary 和 RestoreLongTermRetentionBackup。
'Copy'
'Default'
'OnlineSecondary'
'PointInTimeRestore'
'Recovery'
'Restore'
'RestoreExternalBackup'
'RestoreExternalBackupSecondary'
'RestoreLongTermRetentionBackup'
'Secondary'
elasticPoolId 包含此資料庫之彈性集區的資源標識碼。 字串
encryptionProtector 如果資料庫已針對每個資料庫客戶管理的金鑰進行設定,則為資料庫的 Azure 金鑰保存庫 URI。 字串
encryptionProtectorAutoRotation 啟用或停用資料庫加密保護裝置 AKV 金鑰自動輪替的旗標。 bool
federatedClientId 用於每個資料庫跨租使用者的用戶端標識碼 CMK 案例 string

Constraints:
最小長度 = 36
最大長度 = 36
圖案 = ^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$
freeLimitExhaustionBehavior 指定免費資料庫用完每月可用限制時的行為。

AutoPause:資料庫會在當月剩餘時間的可用限制用盡時自動暫停。

BillForUsage:資料庫會在免費限制用盡時繼續上線,並收取任何超額費用。
'AutoPause'
'BillOverUsage'
highAvailabilityReplicaCount 與用來提供高可用性的商業關鍵、進階或超大規模資料庫相關聯的次要複本數目。 不適用於彈性集區內的超大規模資料庫。 int
isLedgerOn 這個資料庫是否為總賬資料庫,這表示資料庫中的所有數據表都是總賬數據表。 注意:建立資料庫之後,就無法變更此屬性的值。 bool
keys 要使用的使用者指派身分識別的資源標識碼 DatabasePropertiesKeys
licenseType 要套用此資料庫的授權類型。 如果你需要駕照,則是LicenseIncluded;如果你有駕照且符合Azure Hybrid Benefit資格,則是BasePrice 'BasePrice'
'LicenseIncluded'
longTermRetentionBackupResourceId 與此資料庫建立作業相關聯的長期保留備份資源標識符。 字串
maintenanceConfigurationId 指派給資料庫的維護組態標識碼。 此組態會定義維護更新發生的期間。 字串
manualCutover 客戶控制手動完全移轉是否需要在更新資料庫作業期間完成超大規模資料庫層。

只有在將資料庫從業務關鍵/一般用途/進階/標準層調整為超大規模資料庫層時,才適用此屬性。

指定manualCutover時,調整作業會等候使用者輸入觸發超大規模資料庫完全移轉。

若要觸發完全移轉,請在調整作業處於等候狀態時提供 『performCutover』 參數。
bool
maxSizeBytes 以位元組表示的資料庫大小上限。 int
minCapacity 資料庫一律配置的最小容量,如果未暫停,則為 int
performCutover 在調整作業進行中時,觸發客戶控制的手動完全移轉。

這個屬性參數僅適用於起始與 'manualCutover' 參數一起起始的調整作業。

只有當資料庫從業務關鍵/一般用途/進階/標準層調整至超大規模資料庫層級正在進行時,才適用此屬性。

指定了performCutover時,調整作業會觸發完全移轉,並執行超大規模資料庫的角色變更。
bool
preferredEnclaveType 資料庫上要求的記憶體保護區類型,也就是預設或 VBS記憶體保護區。 'Default'
'VBS'
readScale 唯讀路由的狀態。 若啟用,connection string 中應用程式意圖為唯讀的連線,可能會被路由至同一區域內的唯讀次要副本。 不適用於彈性集區內的超大規模資料庫。 'Disabled'
'Enabled'
recoverableDatabaseId 與此資料庫建立作業相關聯的可復原資料庫資源標識符。 字串
recoveryServicesRecoveryPointId 與此資料庫建立作業相關聯的恢復點資源標識碼。 字串
requestedBackupStorageRedundancy 要用來儲存此資料庫的備份的記憶體帳戶類型。 'Geo'
'GeoZone'
'Local'
'Zone'
restorableDroppedDatabaseId 與這個資料庫建立作業相關聯的可還原卸除資料庫資源標識符。 字串
restorePointInTime 指定要還原以建立新資料庫的源資料庫的時間點(ISO8601格式)。 字串
sampleName 建立這個資料庫時要套用的範例架構名稱。 'AdventureWorksLT'
'WideWorldImportersFull'
'WideWorldImportersStd'
secondaryType 如果資料庫是輔助資料庫,則為次要類型。 有效值為 Geo、Named 和 Standby。 'Geo'
'Named'
'Standby'
sourceDatabaseDeletionDate 指定刪除資料庫的時間。 字串
sourceDatabaseId 與這個資料庫建立作業相關聯的源資料庫資源標識符。 字串
sourceResourceId 與這個資料庫建立作業相關聯的來源資源標識符。

只有 DataWarehouse 版本才支援此屬性,而且允許跨訂用帳戶還原。

指定 sourceResourceId 時,sourceDatabaseId、recoverableDatabaseId、restoreableDroppedDatabaseId 和 sourceDatabaseDeletionDate 不得指定,而 CreateMode 必須是 PointInTimeRestore、Restore 或 Recover。

當 createMode 是 PointInTimeRestore 時,sourceResourceId 必須是現有資料庫或現有 sql 集區的資源標識碼,而且必須指定 restorePointInTime。

當 createMode 為 Restore 時,sourceResourceId 必須是可還原卸除資料庫或可還原的已卸除 sql 集區的資源識別符。

當 createMode 為 Recover 時,sourceResourceId 必須是可復原資料庫或可復原 SQL 集區的資源標識碼。

當來源訂用帳戶屬於與目標訂用帳戶不同的租使用者時,“x-ms-authorization-auxiliary” 標頭必須包含來源租使用者的驗證令牌。 如需“x-ms-authorization-auxiliary” 標頭的詳細資訊,請參閱 /azure/azure-resource-manager/management/authenticate-multi-tenant
字串
useFreeLimit 資料庫是否使用免費每月限制。 在訂用帳戶中的一個資料庫上允許。 bool
zoneRedundant 此資料庫是否為區域備援,這表示此資料庫的複本會分散到多個可用性區域。 bool

DatabasePropertiesKeys

Name Description Value

DatabaseUserIdentity

Name Description Value

Sku

Name Description Value
容量 特定 SKU 的容量。 int
family 如果服務有不同世代的硬體,針對相同的 SKU,則可以在這裡擷取。 字串
name SKU 的名稱,通常是字母 + 數位碼,例如 P3。 字串 (必要)
size 特定 SKU 的大小 字串
分層 特定 SKU 的階層或版本,例如基本、進階。 字串

TrackedResourceTags

Name Description Value

使用範例

Bicep 範例

部署 MS SQL 資料庫的基本範例。

param resourceName string = 'acctest0001'
param location string = 'westeurope'
@secure()
@description('The administrator login password for the SQL server')
param administratorLoginPassword string

resource server 'Microsoft.Sql/servers@2021-02-01-preview' = {
  name: resourceName
  location: location
  properties: {
    administratorLogin: 'mradministrator'
    administratorLoginPassword: null
    minimalTlsVersion: '1.2'
    publicNetworkAccess: 'Enabled'
    restrictOutboundNetworkAccess: 'Disabled'
    version: '12.0'
  }
}

resource database 'Microsoft.Sql/servers/databases@2021-02-01-preview' = {
  parent: server
  name: resourceName
  location: location
  properties: {
    autoPauseDelay: 0
    createMode: 'Default'
    elasticPoolId: ''
    highAvailabilityReplicaCount: 0
    isLedgerOn: false
    licenseType: 'LicenseIncluded'
    maintenanceConfigurationId: resourceId('Microsoft.Maintenance/publicMaintenanceConfigurations', 'SQL_Default')
    minCapacity: 0
    readScale: 'Disabled'
    requestedBackupStorageRedundancy: 'Geo'
    zoneRedundant: false
  }
}

Azure 已驗證的模組

以下的 Azure 已驗證模組 可用於部署此資源類型。

模組 Description
Azure SQL Database AVM Resource Module for Azure SQL Database

Azure Quickstart Samples

以下的 Azure 快速啟動範本包含部署此資源類型的Bicep範例。

Bicep檔案 Description
Azure SQL Server 並以 Auditing 寫入 Log Analytics 此範本允許您部署啟用 Auditing 的 Azure SQL 伺服器,將稽核日誌寫入 Log Analytics(OMS 工作空間)
建立SQL Server與資料庫 此範本可讓您建立 SQL Database 和 Server。
專用 SQL 池,具備透明加密 建立 SQL Server 及專用 SQL 池(前稱 SQL DW),並具備 Transparent Data Encryption 功能。
在 Azure 架構 建立一個啟用 ADLS Gen 2 的 Azure 儲存帳號,一個 Azure Data Factory 實例,並連結服務給該儲存帳號(若部署則是 Azure SQL Database),以及一個 Azure Databricks 實例。 部署範本和 ADF 實例受控識別的使用者 AAD 身分識別,將會在記憶體帳戶上授與記憶體 Blob 數據參與者角色。 也有部署 Azure Key Vault 實例、Azure SQL Database 和 Azure Event Hub(用於串流使用案例)的選項。 當 Azure Key Vault 部署時,部署該範本的使用者的資料工廠管理身份與 AAD 身份會被授予 Key Vault Secrets 使用者角色。
私有端點範例 此範本展示了如何建立指向 Azure SQL Server 的私有端點
以 SQL 資料庫配置網頁應用程式 此範本會布建 Web 應用程式、SQL Database、自動調整設定、警示規則和 App Insights。 它會在網頁應用程式中為資料庫配置一個 connection string。
Sonarqube Docker Web App on Linux with Azure SQL 此範本會將 Sonarqube 部署於 Azure App Service 網頁應用 Linux 容器中,使用官方 Sonarqube 映像檔,並由 Azure SQL Server 支援。
Web 應用程式,採用管理身份、SQL Server 與 ΑΙ 簡單範例,用於部署 Azure 基礎設施以支援應用程式 + data + managed identity + monitoring

ARM 樣本資源定義

伺服器/資料庫資源類型可以使用目標作業來部署:

如需每個 API 版本中已變更屬性的清單,請參閱 變更記錄檔

資源格式

創造一個 Microsoft。Sql/servers/databases 資源,請將以下 JSON 加入你的範本。

{
  "type": "Microsoft.Sql/servers/databases",
  "apiVersion": "2025-02-01-preview",
  "name": "string",
  "identity": {
    "type": "string",
    "userAssignedIdentities": {
      "{customized property}": {
      }
    }
  },
  "location": "string",
  "properties": {
    "autoPauseDelay": "int",
    "availabilityZone": "string",
    "catalogCollation": "string",
    "collation": "string",
    "createMode": "string",
    "elasticPoolId": "string",
    "encryptionProtector": "string",
    "encryptionProtectorAutoRotation": "bool",
    "federatedClientId": "string",
    "freeLimitExhaustionBehavior": "string",
    "highAvailabilityReplicaCount": "int",
    "isLedgerOn": "bool",
    "keys": {
      "{customized property}": {
      }
    },
    "licenseType": "string",
    "longTermRetentionBackupResourceId": "string",
    "maintenanceConfigurationId": "string",
    "manualCutover": "bool",
    "maxSizeBytes": "int",
    "minCapacity": "int",
    "performCutover": "bool",
    "preferredEnclaveType": "string",
    "readScale": "string",
    "recoverableDatabaseId": "string",
    "recoveryServicesRecoveryPointId": "string",
    "requestedBackupStorageRedundancy": "string",
    "restorableDroppedDatabaseId": "string",
    "restorePointInTime": "string",
    "sampleName": "string",
    "secondaryType": "string",
    "sourceDatabaseDeletionDate": "string",
    "sourceDatabaseId": "string",
    "sourceResourceId": "string",
    "useFreeLimit": "bool",
    "zoneRedundant": "bool"
  },
  "sku": {
    "capacity": "int",
    "family": "string",
    "name": "string",
    "size": "string",
    "tier": "string"
  },
  "tags": {
    "{customized property}": "string"
  }
}

屬性值

Microsoft。Sql/伺服器/資料庫

Name Description Value
apiVersion API 版本 “2025-02-01-預覽”
身分識別 資料庫的 Azure Active Directory 身份。 DatabaseIdentity
位置 資源所在的地理位置 字串 (必要)
name 資源名稱 字串 (必要)
properties 資源屬性。 DatabaseProperties
sku 資料庫 SKU。

SKU 清單可能會因區域和支援供應項目而異。 要確定在Azure區域內訂閱可用的 SKU(包括 SKU 名稱、階級/版本、家族及容量),請使用 Capabilities_ListByLocation REST API 或以下指令之一:

azurecli<br />az sql db list-editions -l &lt;location&gt; -o table<br />

powershell<br />Get-AzSqlServerServiceObjective -Location &lt;location&gt;<br />
Sku
tags 資源標籤 標記名稱和值的字典。 請參閱範本中的 標籤
型別 資源類型 「Microsoft。SQL/伺服器/資料庫」

DatabaseIdentity

Name Description Value
型別 識別類型 'None'
'UserAssigned'
userAssignedIdentities 要使用的使用者指派身分識別的資源標識碼 DatabaseIdentityUserAssignedIdentities

DatabaseIdentityUserAssignedIdentities

Name Description Value

DatabaseKey

Name Description Value

DatabaseProperties

Name Description Value
autoPauseDelay 在幾分鐘后自動暫停資料庫的時間。 -1 值表示已停用自動暫停 int
availabilityZone 指定資料庫釘選到的可用性區域。 '1'
'2'
'3'
'NoPreference'
catalogCollation 元資料目錄的定序。 'DATABASE_DEFAULT'
'SQL_Latin1_General_CP1_CI_AS'
定序 資料庫的定序。 字串
createMode 指定資料庫建立模式。

默認值:定期建立資料庫。

複製:建立資料庫做為現有資料庫的複本。 sourceDatabaseId 必須指定為源資料庫的資源標識碼。

次要:建立資料庫做為現有資料庫的次要複本。 sourceDatabaseId 必須指定為現有主資料庫的資源標識碼。

PointInTimeRestore:藉由還原現有資料庫的時間點備份來建立資料庫。 sourceDatabaseId 必須指定為現有資料庫的資源標識符,而且必須指定 restorePointInTime。

復原:藉由還原異地復寫備份來建立資料庫。 sourceDatabaseId 必須指定為要還原的可復原資料庫資源標識符。

還原:藉由還原已刪除資料庫的備份來建立資料庫。 必須指定sourceDatabaseId。 如果 sourceDatabaseId 是資料庫的原始資源識別碼,則必須指定 sourceDatabaseDeletionDate。 否則,sourceDatabaseId 必須是可還原的卸除資料庫資源標識符,而且會忽略 sourceDatabaseDeletionDate。 restorePointInTime 也可以指定為從先前的時間點還原。

RestoreLongTermRetentionBackup:從長期保留保存庫還原來建立資料庫。 recoveryServicesRecoveryPointResourceId 必須指定為恢復點資源標識符。

DataWarehouse 版本不支援 Copy、Secondary 和 RestoreLongTermRetentionBackup。
'Copy'
'Default'
'OnlineSecondary'
'PointInTimeRestore'
'Recovery'
'Restore'
'RestoreExternalBackup'
'RestoreExternalBackupSecondary'
'RestoreLongTermRetentionBackup'
'Secondary'
elasticPoolId 包含此資料庫之彈性集區的資源標識碼。 字串
encryptionProtector 如果資料庫已針對每個資料庫客戶管理的金鑰進行設定,則為資料庫的 Azure 金鑰保存庫 URI。 字串
encryptionProtectorAutoRotation 啟用或停用資料庫加密保護裝置 AKV 金鑰自動輪替的旗標。 bool
federatedClientId 用於每個資料庫跨租使用者的用戶端標識碼 CMK 案例 string

Constraints:
最小長度 = 36
最大長度 = 36
圖案 = ^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$
freeLimitExhaustionBehavior 指定免費資料庫用完每月可用限制時的行為。

AutoPause:資料庫會在當月剩餘時間的可用限制用盡時自動暫停。

BillForUsage:資料庫會在免費限制用盡時繼續上線,並收取任何超額費用。
'AutoPause'
'BillOverUsage'
highAvailabilityReplicaCount 與用來提供高可用性的商業關鍵、進階或超大規模資料庫相關聯的次要複本數目。 不適用於彈性集區內的超大規模資料庫。 int
isLedgerOn 這個資料庫是否為總賬資料庫,這表示資料庫中的所有數據表都是總賬數據表。 注意:建立資料庫之後,就無法變更此屬性的值。 bool
keys 要使用的使用者指派身分識別的資源標識碼 DatabasePropertiesKeys
licenseType 要套用此資料庫的授權類型。 如果你需要駕照,則是LicenseIncluded;如果你有駕照且符合Azure Hybrid Benefit資格,則是BasePrice 'BasePrice'
'LicenseIncluded'
longTermRetentionBackupResourceId 與此資料庫建立作業相關聯的長期保留備份資源標識符。 字串
maintenanceConfigurationId 指派給資料庫的維護組態標識碼。 此組態會定義維護更新發生的期間。 字串
manualCutover 客戶控制手動完全移轉是否需要在更新資料庫作業期間完成超大規模資料庫層。

只有在將資料庫從業務關鍵/一般用途/進階/標準層調整為超大規模資料庫層時,才適用此屬性。

指定manualCutover時,調整作業會等候使用者輸入觸發超大規模資料庫完全移轉。

若要觸發完全移轉,請在調整作業處於等候狀態時提供 『performCutover』 參數。
bool
maxSizeBytes 以位元組表示的資料庫大小上限。 int
minCapacity 資料庫一律配置的最小容量,如果未暫停,則為 int
performCutover 在調整作業進行中時,觸發客戶控制的手動完全移轉。

這個屬性參數僅適用於起始與 'manualCutover' 參數一起起始的調整作業。

只有當資料庫從業務關鍵/一般用途/進階/標準層調整至超大規模資料庫層級正在進行時,才適用此屬性。

指定了performCutover時,調整作業會觸發完全移轉,並執行超大規模資料庫的角色變更。
bool
preferredEnclaveType 資料庫上要求的記憶體保護區類型,也就是預設或 VBS記憶體保護區。 'Default'
'VBS'
readScale 唯讀路由的狀態。 若啟用,connection string 中應用程式意圖為唯讀的連線,可能會被路由至同一區域內的唯讀次要副本。 不適用於彈性集區內的超大規模資料庫。 'Disabled'
'Enabled'
recoverableDatabaseId 與此資料庫建立作業相關聯的可復原資料庫資源標識符。 字串
recoveryServicesRecoveryPointId 與此資料庫建立作業相關聯的恢復點資源標識碼。 字串
requestedBackupStorageRedundancy 要用來儲存此資料庫的備份的記憶體帳戶類型。 'Geo'
'GeoZone'
'Local'
'Zone'
restorableDroppedDatabaseId 與這個資料庫建立作業相關聯的可還原卸除資料庫資源標識符。 字串
restorePointInTime 指定要還原以建立新資料庫的源資料庫的時間點(ISO8601格式)。 字串
sampleName 建立這個資料庫時要套用的範例架構名稱。 'AdventureWorksLT'
'WideWorldImportersFull'
'WideWorldImportersStd'
secondaryType 如果資料庫是輔助資料庫,則為次要類型。 有效值為 Geo、Named 和 Standby。 'Geo'
'Named'
'Standby'
sourceDatabaseDeletionDate 指定刪除資料庫的時間。 字串
sourceDatabaseId 與這個資料庫建立作業相關聯的源資料庫資源標識符。 字串
sourceResourceId 與這個資料庫建立作業相關聯的來源資源標識符。

只有 DataWarehouse 版本才支援此屬性,而且允許跨訂用帳戶還原。

指定 sourceResourceId 時,sourceDatabaseId、recoverableDatabaseId、restoreableDroppedDatabaseId 和 sourceDatabaseDeletionDate 不得指定,而 CreateMode 必須是 PointInTimeRestore、Restore 或 Recover。

當 createMode 是 PointInTimeRestore 時,sourceResourceId 必須是現有資料庫或現有 sql 集區的資源標識碼,而且必須指定 restorePointInTime。

當 createMode 為 Restore 時,sourceResourceId 必須是可還原卸除資料庫或可還原的已卸除 sql 集區的資源識別符。

當 createMode 為 Recover 時,sourceResourceId 必須是可復原資料庫或可復原 SQL 集區的資源標識碼。

當來源訂用帳戶屬於與目標訂用帳戶不同的租使用者時,“x-ms-authorization-auxiliary” 標頭必須包含來源租使用者的驗證令牌。 如需“x-ms-authorization-auxiliary” 標頭的詳細資訊,請參閱 /azure/azure-resource-manager/management/authenticate-multi-tenant
字串
useFreeLimit 資料庫是否使用免費每月限制。 在訂用帳戶中的一個資料庫上允許。 bool
zoneRedundant 此資料庫是否為區域備援,這表示此資料庫的複本會分散到多個可用性區域。 bool

DatabasePropertiesKeys

Name Description Value

DatabaseUserIdentity

Name Description Value

Sku

Name Description Value
容量 特定 SKU 的容量。 int
family 如果服務有不同世代的硬體,針對相同的 SKU,則可以在這裡擷取。 字串
name SKU 的名稱,通常是字母 + 數位碼,例如 P3。 字串 (必要)
size 特定 SKU 的大小 字串
分層 特定 SKU 的階層或版本,例如基本、進階。 字串

TrackedResourceTags

Name Description Value

使用範例

Azure Quickstart templates

以下的 Azure 快速起始範本部署此資源類型。

Template Description
Azure SQL Server 並以 Auditing 寫入 Log Analytics

部署至Azure
此範本允許您部署啟用 Auditing 的 Azure SQL 伺服器,將稽核日誌寫入 Log Analytics(OMS 工作空間)
建立SQL Server與資料庫

部署至Azure
此範本可讓您建立 SQL Database 和 Server。
專用 SQL 池,具備透明加密

部署至Azure
建立 SQL Server 及專用 SQL 池(前稱 SQL DW),並具備 Transparent Data Encryption 功能。
部署新的 SQL 彈性池

部署至Azure
此範本允許您部署新的 SQL 彈性池,並附帶其新關聯的 SQL Server 及可指派的新 SQL 資料庫。
在 Azure 架構

部署至Azure
建立一個啟用 ADLS Gen 2 的 Azure 儲存帳號,一個 Azure Data Factory 實例,並連結服務給該儲存帳號(若部署則是 Azure SQL Database),以及一個 Azure Databricks 實例。 部署範本和 ADF 實例受控識別的使用者 AAD 身分識別,將會在記憶體帳戶上授與記憶體 Blob 數據參與者角色。 也有部署 Azure Key Vault 實例、Azure SQL Database 和 Azure Event Hub(用於串流使用案例)的選項。 當 Azure Key Vault 部署時,部署該範本的使用者的資料工廠管理身份與 AAD 身份會被授予 Key Vault Secrets 使用者角色。
HDInsight 搭配自訂的 Ambari + Hive Metastore 資料庫,VNET

部署至Azure
此範本可讓您使用新的 SQL DB,在現有的虛擬網路中建立 HDInsight 叢集,以作為自訂 Ambari DB 和 Hive 中繼存放區。 您必須擁有現有的 SQL Sever、記憶體帳戶和 VNET。
私有端點範例

部署至Azure
此範本展示了如何建立指向 Azure SQL Server 的私有端點
以 SQL 資料庫配置網頁應用程式

部署至Azure
此範本會布建 Web 應用程式、SQL Database、自動調整設定、警示規則和 App Insights。 它會在網頁應用程式中為資料庫配置一個 connection string。
Remote Desktop 具備高可用性的服務

部署至Azure
此 ARM 範本範例程式碼將部署一個 Remote Desktop服務 2019 會話集合實驗室,且具備高可用性。 目標是部署一個完全冗餘且高度可用的 Remote Desktop 服務解決方案,使用 Windows Server 2019。
Sonarqube Docker Web App on Linux with Azure SQL

部署至Azure
此範本會將 Sonarqube 部署於 Azure App Service 網頁應用 Linux 容器中,使用官方 Sonarqube 映像檔,並由 Azure SQL Server 支援。
Web 應用程式,採用管理身份、SQL Server 與 ΑΙ

部署至Azure
簡單範例,用於部署 Azure 基礎設施以支援應用程式 + data + managed identity + monitoring
WebApp 正在消耗Azure SQL私有端點

部署至Azure
此範本展示了如何建立一個使用指向 Azure SQL Server 的私有端點的網頁應用程式

Terraform (AzAPI 提供者) 資源定義

伺服器/資料庫資源類型可以使用目標作業來部署:

  • 資源群組

如需每個 API 版本中已變更屬性的清單,請參閱 變更記錄檔

資源格式

創造一個 Microsoft。Sql/servers/databases 資源,請將以下 Terraform 加入你的範本。

resource "azapi_resource" "symbolicname" {
  type = "Microsoft.Sql/servers/databases@2025-02-01-preview"
  name = "string"
  parent_id = "string"
  identity {
    type = "string"
    identity_ids = [
      "string"
    ]
  }
  location = "string"
  tags = {
    {customized property} = "string"
  }
  body = {
    properties = {
      autoPauseDelay = int
      availabilityZone = "string"
      catalogCollation = "string"
      collation = "string"
      createMode = "string"
      elasticPoolId = "string"
      encryptionProtector = "string"
      encryptionProtectorAutoRotation = bool
      federatedClientId = "string"
      freeLimitExhaustionBehavior = "string"
      highAvailabilityReplicaCount = int
      isLedgerOn = bool
      keys = {
        {customized property} = {
        }
      }
      licenseType = "string"
      longTermRetentionBackupResourceId = "string"
      maintenanceConfigurationId = "string"
      manualCutover = bool
      maxSizeBytes = int
      minCapacity = int
      performCutover = bool
      preferredEnclaveType = "string"
      readScale = "string"
      recoverableDatabaseId = "string"
      recoveryServicesRecoveryPointId = "string"
      requestedBackupStorageRedundancy = "string"
      restorableDroppedDatabaseId = "string"
      restorePointInTime = "string"
      sampleName = "string"
      secondaryType = "string"
      sourceDatabaseDeletionDate = "string"
      sourceDatabaseId = "string"
      sourceResourceId = "string"
      useFreeLimit = bool
      zoneRedundant = bool
    }
    sku = {
      capacity = int
      family = "string"
      name = "string"
      size = "string"
      tier = "string"
    }
  }
}

屬性值

Microsoft。Sql/伺服器/資料庫

Name Description Value
身分識別 資料庫的 Azure Active Directory 身份。 DatabaseIdentity
位置 資源所在的地理位置 字串 (必要)
name 資源名稱 字串 (必要)
parent_id 此資源為父系之資源的標識碼。 類型資源的標識碼:伺服器
properties 資源屬性。 DatabaseProperties
sku 資料庫 SKU。

SKU 清單可能會因區域和支援供應項目而異。 要確定在Azure區域內訂閱可用的 SKU(包括 SKU 名稱、階級/版本、家族及容量),請使用 Capabilities_ListByLocation REST API 或以下指令之一:

azurecli<br />az sql db list-editions -l &lt;location&gt; -o table<br />

powershell<br />Get-AzSqlServerServiceObjective -Location &lt;location&gt;<br />
Sku
tags 資源標籤 標記名稱和值的字典。
型別 資源類型 「Microsoft。Sql/servers/databases@2025-02-01-preview”

DatabaseIdentity

Name Description Value
型別 識別類型 'None'
'UserAssigned'
userAssignedIdentities 要使用的使用者指派身分識別的資源標識碼 DatabaseIdentityUserAssignedIdentities

DatabaseIdentityUserAssignedIdentities

Name Description Value

DatabaseKey

Name Description Value

DatabaseProperties

Name Description Value
autoPauseDelay 在幾分鐘后自動暫停資料庫的時間。 -1 值表示已停用自動暫停 int
availabilityZone 指定資料庫釘選到的可用性區域。 '1'
'2'
'3'
'NoPreference'
catalogCollation 元資料目錄的定序。 'DATABASE_DEFAULT'
'SQL_Latin1_General_CP1_CI_AS'
定序 資料庫的定序。 字串
createMode 指定資料庫建立模式。

默認值:定期建立資料庫。

複製:建立資料庫做為現有資料庫的複本。 sourceDatabaseId 必須指定為源資料庫的資源標識碼。

次要:建立資料庫做為現有資料庫的次要複本。 sourceDatabaseId 必須指定為現有主資料庫的資源標識碼。

PointInTimeRestore:藉由還原現有資料庫的時間點備份來建立資料庫。 sourceDatabaseId 必須指定為現有資料庫的資源標識符,而且必須指定 restorePointInTime。

復原:藉由還原異地復寫備份來建立資料庫。 sourceDatabaseId 必須指定為要還原的可復原資料庫資源標識符。

還原:藉由還原已刪除資料庫的備份來建立資料庫。 必須指定sourceDatabaseId。 如果 sourceDatabaseId 是資料庫的原始資源識別碼,則必須指定 sourceDatabaseDeletionDate。 否則,sourceDatabaseId 必須是可還原的卸除資料庫資源標識符,而且會忽略 sourceDatabaseDeletionDate。 restorePointInTime 也可以指定為從先前的時間點還原。

RestoreLongTermRetentionBackup:從長期保留保存庫還原來建立資料庫。 recoveryServicesRecoveryPointResourceId 必須指定為恢復點資源標識符。

DataWarehouse 版本不支援 Copy、Secondary 和 RestoreLongTermRetentionBackup。
'Copy'
'Default'
'OnlineSecondary'
'PointInTimeRestore'
'Recovery'
'Restore'
'RestoreExternalBackup'
'RestoreExternalBackupSecondary'
'RestoreLongTermRetentionBackup'
'Secondary'
elasticPoolId 包含此資料庫之彈性集區的資源標識碼。 字串
encryptionProtector 如果資料庫已針對每個資料庫客戶管理的金鑰進行設定,則為資料庫的 Azure 金鑰保存庫 URI。 字串
encryptionProtectorAutoRotation 啟用或停用資料庫加密保護裝置 AKV 金鑰自動輪替的旗標。 bool
federatedClientId 用於每個資料庫跨租使用者的用戶端標識碼 CMK 案例 string

Constraints:
最小長度 = 36
最大長度 = 36
圖案 = ^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$
freeLimitExhaustionBehavior 指定免費資料庫用完每月可用限制時的行為。

AutoPause:資料庫會在當月剩餘時間的可用限制用盡時自動暫停。

BillForUsage:資料庫會在免費限制用盡時繼續上線,並收取任何超額費用。
'AutoPause'
'BillOverUsage'
highAvailabilityReplicaCount 與用來提供高可用性的商業關鍵、進階或超大規模資料庫相關聯的次要複本數目。 不適用於彈性集區內的超大規模資料庫。 int
isLedgerOn 這個資料庫是否為總賬資料庫,這表示資料庫中的所有數據表都是總賬數據表。 注意:建立資料庫之後,就無法變更此屬性的值。 bool
keys 要使用的使用者指派身分識別的資源標識碼 DatabasePropertiesKeys
licenseType 要套用此資料庫的授權類型。 如果你需要駕照,則是LicenseIncluded;如果你有駕照且符合Azure Hybrid Benefit資格,則是BasePrice 'BasePrice'
'LicenseIncluded'
longTermRetentionBackupResourceId 與此資料庫建立作業相關聯的長期保留備份資源標識符。 字串
maintenanceConfigurationId 指派給資料庫的維護組態標識碼。 此組態會定義維護更新發生的期間。 字串
manualCutover 客戶控制手動完全移轉是否需要在更新資料庫作業期間完成超大規模資料庫層。

只有在將資料庫從業務關鍵/一般用途/進階/標準層調整為超大規模資料庫層時,才適用此屬性。

指定manualCutover時,調整作業會等候使用者輸入觸發超大規模資料庫完全移轉。

若要觸發完全移轉,請在調整作業處於等候狀態時提供 『performCutover』 參數。
bool
maxSizeBytes 以位元組表示的資料庫大小上限。 int
minCapacity 資料庫一律配置的最小容量,如果未暫停,則為 int
performCutover 在調整作業進行中時,觸發客戶控制的手動完全移轉。

這個屬性參數僅適用於起始與 'manualCutover' 參數一起起始的調整作業。

只有當資料庫從業務關鍵/一般用途/進階/標準層調整至超大規模資料庫層級正在進行時,才適用此屬性。

指定了performCutover時,調整作業會觸發完全移轉,並執行超大規模資料庫的角色變更。
bool
preferredEnclaveType 資料庫上要求的記憶體保護區類型,也就是預設或 VBS記憶體保護區。 'Default'
'VBS'
readScale 唯讀路由的狀態。 若啟用,connection string 中應用程式意圖為唯讀的連線,可能會被路由至同一區域內的唯讀次要副本。 不適用於彈性集區內的超大規模資料庫。 'Disabled'
'Enabled'
recoverableDatabaseId 與此資料庫建立作業相關聯的可復原資料庫資源標識符。 字串
recoveryServicesRecoveryPointId 與此資料庫建立作業相關聯的恢復點資源標識碼。 字串
requestedBackupStorageRedundancy 要用來儲存此資料庫的備份的記憶體帳戶類型。 'Geo'
'GeoZone'
'Local'
'Zone'
restorableDroppedDatabaseId 與這個資料庫建立作業相關聯的可還原卸除資料庫資源標識符。 字串
restorePointInTime 指定要還原以建立新資料庫的源資料庫的時間點(ISO8601格式)。 字串
sampleName 建立這個資料庫時要套用的範例架構名稱。 'AdventureWorksLT'
'WideWorldImportersFull'
'WideWorldImportersStd'
secondaryType 如果資料庫是輔助資料庫,則為次要類型。 有效值為 Geo、Named 和 Standby。 'Geo'
'Named'
'Standby'
sourceDatabaseDeletionDate 指定刪除資料庫的時間。 字串
sourceDatabaseId 與這個資料庫建立作業相關聯的源資料庫資源標識符。 字串
sourceResourceId 與這個資料庫建立作業相關聯的來源資源標識符。

只有 DataWarehouse 版本才支援此屬性,而且允許跨訂用帳戶還原。

指定 sourceResourceId 時,sourceDatabaseId、recoverableDatabaseId、restoreableDroppedDatabaseId 和 sourceDatabaseDeletionDate 不得指定,而 CreateMode 必須是 PointInTimeRestore、Restore 或 Recover。

當 createMode 是 PointInTimeRestore 時,sourceResourceId 必須是現有資料庫或現有 sql 集區的資源標識碼,而且必須指定 restorePointInTime。

當 createMode 為 Restore 時,sourceResourceId 必須是可還原卸除資料庫或可還原的已卸除 sql 集區的資源識別符。

當 createMode 為 Recover 時,sourceResourceId 必須是可復原資料庫或可復原 SQL 集區的資源標識碼。

當來源訂用帳戶屬於與目標訂用帳戶不同的租使用者時,“x-ms-authorization-auxiliary” 標頭必須包含來源租使用者的驗證令牌。 如需“x-ms-authorization-auxiliary” 標頭的詳細資訊,請參閱 /azure/azure-resource-manager/management/authenticate-multi-tenant
字串
useFreeLimit 資料庫是否使用免費每月限制。 在訂用帳戶中的一個資料庫上允許。 bool
zoneRedundant 此資料庫是否為區域備援,這表示此資料庫的複本會分散到多個可用性區域。 bool

DatabasePropertiesKeys

Name Description Value

DatabaseUserIdentity

Name Description Value

Sku

Name Description Value
容量 特定 SKU 的容量。 int
family 如果服務有不同世代的硬體,針對相同的 SKU,則可以在這裡擷取。 字串
name SKU 的名稱,通常是字母 + 數位碼,例如 P3。 字串 (必要)
size 特定 SKU 的大小 字串
分層 特定 SKU 的階層或版本,例如基本、進階。 字串

TrackedResourceTags

Name Description Value

使用範例

Terraform 範例

部署 MS SQL 資料庫的基本範例。

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

provider "azurerm" {
  features {
  }
}

provider "azapi" {
  skip_provider_registration = false
}

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

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

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

data "azurerm_client_config" "current" {
}

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-02-01-preview"
  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    = ["*"]
}

data "azapi_resource_id" "publicMaintenanceConfiguration" {
  type      = "Microsoft.Maintenance/publicMaintenanceConfigurations@2023-04-01"
  parent_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
  name      = "SQL_Default"
}

resource "azapi_resource" "database" {
  type      = "Microsoft.Sql/servers/databases@2021-02-01-preview"
  parent_id = azapi_resource.server.id
  name      = var.resource_name
  location  = var.location
  body = {
    properties = {
      autoPauseDelay                   = 0
      createMode                       = "Default"
      elasticPoolId                    = ""
      highAvailabilityReplicaCount     = 0
      isLedgerOn                       = false
      licenseType                      = "LicenseIncluded"
      maintenanceConfigurationId       = data.azapi_resource_id.publicMaintenanceConfiguration.id
      minCapacity                      = 0
      readScale                        = "Disabled"
      requestedBackupStorageRedundancy = "Geo"
      zoneRedundant                    = false
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

部署 MS SQL 資料庫的基本範例。

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

provider "azurerm" {
  features {
  }
}

provider "azapi" {
  skip_provider_registration = false
}

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

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

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

data "azurerm_client_config" "current" {
}

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-02-01-preview"
  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    = ["*"]
}

data "azapi_resource_id" "publicMaintenanceConfiguration" {
  type      = "Microsoft.Maintenance/publicMaintenanceConfigurations@2023-04-01"
  parent_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
  name      = "SQL_Default"
}

resource "azapi_resource" "database" {
  type      = "Microsoft.Sql/servers/databases@2021-02-01-preview"
  parent_id = azapi_resource.server.id
  name      = var.resource_name
  location  = var.location
  body = {
    properties = {
      autoPauseDelay                   = 0
      createMode                       = "Default"
      elasticPoolId                    = ""
      highAvailabilityReplicaCount     = 0
      isLedgerOn                       = false
      licenseType                      = "LicenseIncluded"
      maintenanceConfigurationId       = data.azapi_resource_id.publicMaintenanceConfiguration.id
      minCapacity                      = 0
      readScale                        = "Disabled"
      requestedBackupStorageRedundancy = "Geo"
      zoneRedundant                    = false
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}