You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure SQL数据库KQL查询SKU名称返回null,如何解决?

解决Azure SQL数据库SKU名称获取问题

你当前查询的是SQL服务器资源(microsoft.sql/servers),而SKU名称(如generalpurpose)属于SQL数据库资源(microsoft.sql/servers/databases),所以直接从服务器资源中提取SKU字段会返回null。要实现获取SKU名称的需求,需要关联对应的数据库资源,修改后的查询语句如下:

// Azure Resource Graph Query
// 查找未分配可用区的SQL数据库及其SKU
Resources
| where type == "microsoft.sql/servers"
| where isnull(zones)
| where location == 'australiaeast'
// 关联对应的SQL数据库资源,提取SKU信息
| join kind=leftouter (
    Resources
    | where type == "microsoft.sql/servers/databases"
    | extend serverId = substring(id, 0, indexof(id, '/databases'))
    | project serverId, SkuName = tostring(sku.tier), DatabaseName = name
) on $left.id == $right.serverId
// 关联订阅名称
| join kind=leftouter ( 
    resourcecontainers
    | where type == "microsoft.resources/subscriptions"
    | extend resolvedSubId = tostring(split(id, '/', 2)[0]), subscriptionName = name
    | project resolvedSubId, subscriptionName
) on $left.subscriptionId == $right.resolvedSubId
| project 
    recommendationId = "DB", 
    DatabaseName, 
    subscriptionId, 
    subscriptionName, 
    location, 
    AvaiabilityZone="Zones: No Zone", 
    resourceGroup, 
    SkuName,
    ServerName = name

关键说明:

  • 通过左连接关联microsoft.sql/servers/databases资源,利用服务器ID匹配对应的数据库
  • 使用sku.tier字段提取SKU层级名称(即你需要的generalpurpose、basic等类型)
  • 新增ServerName字段区分服务器名称和数据库名称,避免字段混淆

内容的提问来源于stack exchange,提问作者Vince

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 23:20:26