Azure SQL Database 的 Azure CLI 範例Azure CLI samples for Azure SQL Database

您可以使用 Azure CLI 來設定 Azure SQL Database。Azure SQL Database can be configured using Azure CLI.

如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶If you don't have an Azure subscription, create a free account before you begin.

使用 Azure Cloud ShellUse Azure Cloud Shell

Azure Cloud Shell 是裝載於 Azure 中的互動式殼層環境,可在瀏覽器中使用。Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. Cloud Shell 可讓您使用 bashPowerShell 以與 Azure 服務搭配使用。Cloud Shell lets you use either bash or PowerShell to work with Azure services. Azure Cloud Shell 已預先安裝一些命令,可讓您執行本文提到的程式碼,而不必在本機環境上安裝任何工具。You can use the Cloud Shell pre-installed commands to run the code in this article without having to install anything on your local environment.

若要啟動 Azure Cloud Shell:To launch Azure Cloud Shell:

選項Option 範例/連結Example/Link
選取程式碼區塊右上角的 [試試看] 。Select Try It in the upper-right corner of a code block. 選取 [試用] 並不會自動將程式碼複製到 Cloud Shell 中。Selecting Try It doesn't automatically copy the code to Cloud Shell. Azure Cloud Shell 的試試看範例
請前往 或選取 [啟動 Cloud Shell] 按鈕,在瀏覽器中開啟 Cloud Shell。Go to or select the Launch Cloud Shell button to open Cloud Shell in your browser. 在新視窗中啟動 Cloud ShellLaunch Cloud Shell in a new window
選取 Azure 入口網站右上角功能表列中的 [Cloud Shell] 按鈕。Select the Cloud Shell button on the top-right menu bar in the Azure portal. Azure 入口網站中的 [Cloud Shell] 按鈕

若要在 Azure Cloud Shell 中執行本文中的程式碼:To run the code in this article in Azure Cloud Shell:

  1. 啟動 Cloud Shell。Launch Cloud Shell.
  2. 選取程式碼區塊上的 [複製] 按鈕,複製程式碼。Select the Copy button on a code block to copy the code.
  3. 在 Windows 和 Linux 上按 Ctrl+Shift+V;或在 macOS 上按 Cmd+Shift+V,將程式碼貼到 Cloud Shell工作階段中。Paste the code into the Cloud Shell session with Ctrl+Shift+V on Windows and Linux, or Cmd+Shift+V on macOS.
  4. 按下 Enter 鍵執行程式碼。Press Enter to run the code.

如果您選擇在本機安裝和使用 CLI,本主題會要求您執行 Azure CLI 2.0 版或更新版本。If you choose to install and use the CLI locally, this topic requires that you are running the Azure CLI version 2.0 or later. 執行 az --version 以尋找版本。Run az --version to find the version. 如果您需要安裝或升級,請參閱安裝 Azure CLIIf you need to install or upgrade, see Install the Azure CLI.

單一資料庫與彈性集區Single database & Elastic pools

下表包含適用於 Azure SQL Database 之 Azure CLI 指令碼範例的連結。The following table includes links to Azure CLI script examples for Azure SQL Database.

建立單一資料庫和彈性集區Create a single database and an elastic pool
建立單一資料庫並設定防火牆規則Create a single database and configure a firewall rule 此 CLI 指令碼範例會建立單一 Azure SQL 資料庫,並設定伺服器層級防火牆規則。This CLI script example creates a single Azure SQL database and configures a server-level firewall rule.
建立彈性集區並移動集區資料庫Create elastic pools and move pooled databases 此CLI 指令碼範例會建立 SQL 彈性集區,並移動集區 Azure SQL 資料庫,然後變更計算大小。This CLI script example creates SQL elastic pools, and moves pooled Azure SQL databases, and changes compute sizes.
調整單一資料庫和彈性集區Scale a single database and an elastic pool
調整單一資料庫Scale a single database 此 CLI 指令碼範例會在查詢單一 Azure SQL 資料庫的大小資訊後,將其調整為不同的計算大小。This CLI script example scales a single Azure SQL database to a different compute size after querying the size information for the database.
調整彈性集區Scale an elastic pool 此 CLI 指令碼範例會將 SQL 彈性集區調整為不同的計算大小。This CLI script example scales a SQL elastic pool to a different compute size.
容錯移轉群組Failover groups
將單一資料庫新增至容錯移轉群組Add single database to failover group 此 CLI 指令碼會建立資料庫和容錯移轉群組,將資料庫新增至容錯移轉群組,並測試容錯移轉至次要伺服器。This CLI script creates a database, and a failover group, adds the database to the failover group and tests failover to the secondary server.

深入了解單一資料庫 Azure CLI APILearn more about the Single Database Azure CLI API.

受控執行個體Managed Instance

下表包含適用於 Azure SQL Database 之 Azure CLI 指令碼範例的連結 - 受控執行個體。The following table includes links to Azure CLI script examples for Azure SQL Database - Managed Instance.

建立受控執行個體Create a Managed Instance 此 CLI 指令碼示範如何建立受控執行個體。This CLI script shows how to create a Managed Instance.
更新受控執行個體Update a Managed Instance 此 CLI 指令碼示範如何更新受控執行個體。This CLI script shows how to update a Managed Instance.
將資料庫移到另一個受控執行個體Move a database to another Managed Instance 此 CLI 指令碼示範如何將資料庫的備份從一個執行個體還原到另一個執行個體。This CLI script shows how to restore a backup of a database from one instance to another.

深入了解受控執行個體 Azure CLI API 並尋找其他範例Learn more about the Managed Instance Azure CLI API and find additional examples here.