檢視 SQL Server 資料庫 - Azure Arc

適用於:SQL Server

您可以在 Azure 中進行清查和檢視 SQL Server 資料庫。

必要條件

開始之前,請確認裝載資料庫的 SQL Server 執行個體符合以下描述:

  • 裝載在執行 Windows 作業系統的實體或虛擬機器上。
  • 是 SQL Server 2014 (12.x) 或更新版本。
  • 已連線至 Azure Arc。請參閱將 SQL Server 連線到 Azure Arc
  • 已直接或透過 Proxy 伺服器連線到網際網路。
  • 請確定資料庫名稱遵守命名慣例,且不包含保留字。 如需保留字的清單,請參閱解決保留資源名稱的錯誤
  • 若要檢視可用的資料庫大小和空間,請提供下列權限:
    • 內建 SQL Server 登入 NT AUTHORITY\SYSTEM 針對電腦上執行的所有 SQL Server 執行個體,必須是 SQL Server sysadmin 伺服器角色的成員。

清查資料庫

  1. 在 Azure 入口網站中找到透過 Azure Arc 啟用的 SQL Server 執行個體。
  2. 選取 SQL Server 資源。
  3. 在 [資料管理] 下,選取 [資料庫]。

Azure 入口網站顯示 SQL Server 資料庫 - Azure Arc。使用此區域來檢視屬於執行個體的資料庫。

檢視資料庫屬性

若要檢視特定資料庫的資料庫屬性,請在入口網站上選取資料庫。

建立、修改或刪除資料庫之後,變更會在一小時內於 Azure 入口網站顯示。

Screenshot of Azure portal, SQL Server database properties.

在 [資料庫] 頁面上,會看到下列資訊:

  • 資料收集和上傳的相關資訊:
    • 上次收集的時間
    • 上傳狀態
  • 每個資料庫的相關資訊:
    • 名稱
    • 狀態
    • 建立時間
    • 最早的還原點

當選取特定資料庫時,您會看到該資料庫的所有屬性,這些屬性也會顯示在 SQL Server Management Studio (SSMS) 中。

Screenshot of full database property list.

如何使用 Azure Resource Graph 來查詢資料

以下是一些範例案例,示範如何使用 Azure Resource Graph 來查詢檢視透過 Azure Arc 啟用的 SQL Server 資料庫時可用的資料。

案例 1:取得 10 個資料庫

取得 10 個資料庫,並傳回可供查詢的屬性:

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances/databases'
| limit 10

要查詢的許多最有趣的屬性都位於 properties 屬性中。 若要探索可用的屬性,請執行此查詢,然後選取 [查看資料列的詳細資料]。 這會傳回右側 JSON 檢視器中的屬性。

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances/databases'
| project properties

您可以使用屬性 JSON 每個層級之間的句點來導覽屬性 JSON 的階層。

案例 2:取得所有資料庫選項 AUTO_CLOSE 設為 ON 的資料庫

| where (type == 'microsoft.azurearcdata/sqlserverinstances/databases' and properties.databaseOptions.isAutoCloseOn == true)
| extend isAutoCloseOn = properties.databaseOptions.isAutoCloseOn
| project name, isAutoCloseOn

案例 3:取得已加密與未加密的資料庫計數

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances/databases'
| extend isEncrypted = properties.databaseOptions.isEncrypted
| summarize count() by tostring(isEncrypted)
| order by ['isEncrypted'] asc

案例 4:顯示所有未加密的資料庫

resources
| where (type == 'microsoft.azurearcdata/sqlserverinstances/databases' and properties.databaseOptions.isEncrypted == false)
| extend isEncrypted = properties.databaseOptions.isEncrypted
| project name, isEncrypted

案例 5:依區域和相容性層級取得所有資料庫

此範例會傳回 westus3 位置中相容性層級為 160 的所有資料庫:

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances/databases'
| where location == "westus3"
| where properties.compatibilityLevel == "160"

案例 6:顯示 SQL Server 版本散發

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances'
| extend SQLversion = properties.version
| summarize count() by tostring(SQLversion)

案例 7:依相容性顯示資料庫計數

此範例會傳回依相容性層級排序的資料庫數目:

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances/databases'
| summarize count() by tostring(properties.compatibilityLevel)
| order by properties_compatibilityLevel asc

您也可以建立圖表,並將其釘選到儀表板

Diagram of a pie chart that displays the query results for the count of databases by compatibility level.

已知問題

Azure 上可能不會立即刪除已在內部部署中刪除的資料庫。 資料庫 CRUD 作業在內部部署中的執行方式不會受影響。