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 ShellOpen Azure Cloud Shell

Azure Cloud Shell 是裝載於 Azure 中的互動式殼層環境,並且會透過瀏覽器來使用。Azure Cloud Shell is an interactive shell environment hosted in Azure and used through your browse. Azure Cloud Shell 可讓您使用 bashPowerShell 殼層來執行各種可與 Azure 服務搭配運作的工具。Azure Cloud Shell allows you to use either bash or PowerShell shells to run a variety of tools to work with Azure services. Azure Cloud Shell 已預先安裝一些命令,可讓您執行本文的內容,而不必在本機環境上安裝任何工具。Azure Cloud Shell comes pre-installed with the commands to allow you to run the content of this article without having to install anything on your local environment.

若要在 Azure Cloud Shell 上執行本文所包含的任何程式碼,請開啟 Cloud Shell 工作階段、使用某個程式碼區塊上的 [複製] 按鈕來複製程式碼,然後使用 Ctrl+Shift+V (在 Windows 和 Linux 上) 或 Cmd+Shift+V (在 macOS 上) 將程式碼貼到 Cloud Shell 工作階段中。To run any code contained in this article on Azure Cloud Shell, open a Cloud Shell session, use the Copy button on a code block to copy the code, and paste it into the Cloud Shell session with Ctrl+Shift+V on Windows and Linux, or Cmd+Shift+V on macOS. 貼上的文字不會自動執行,因此請按 Enter 來執行程式碼。Pasted text is not automatically executed, so press Enter to run code.

您可以使用下列方式來啟動 Azure Cloud Shell:You can launch Azure Cloud Shell with:

選取程式碼區塊右上角的 [試試看] 。Select Try It in the upper-right corner of a code block. 這__不會__自動將文字複製到 Cloud Shell。This doesn't automatically copy text to Cloud Shell. Azure Cloud Shell 的試試看範例
在瀏覽器中開啟 shell.azure.comOpen shell.azure.com in your browser. 啟動 Azure Cloud Shell 按鈕Launch Azure Cloud Shell button
選取 Azure 入口網站右上角功能表上的 [Cloud Shell] 按鈕。Select the Cloud Shell button on the menu in the upper-right corner of the Azure portal. Azure 入口網站中的 [Cloud Shell] 按鈕

如果您選擇在本機安裝和使用 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.

深入了解單一資料庫 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.