快速入門:使用 Azure 入口網站在 Azure SQL Database 中建立單一資料庫Quickstart: Create a single database in Azure SQL Database using the Azure portal

要在 Azure SQL Database 中建立資料庫,建立單一資料庫是最快速且最簡單的部署選項。Creating a single database is the quickest and simplest deployment option for creating a database in Azure SQL Database. 本快速入門說明如何使用 Azure 入口網站建立並查詢單一資料庫。This quickstart shows you how to create and then query a single database using the Azure portal.

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

若要進行本快速入門中的所有步驟,請登入 Azure 入口網站For all steps in this quickstart, sign in to the Azure portal.

建立單一資料庫Create a single database

您可以在已佈建的或無伺服器 (預覽) 計算層中建立單一資料庫。A single database can either be created in the provisioned or serverless (preview) compute tier.

  • 已佈建計算層中的單一資料庫具有已定義數量的預先配置計算資源,以及一組使用兩種購買模型之一的記憶體和儲存體資源。A single database in the provisioned compute tier has a defined amount of pre-allocated compute resources plus a set of memory and storage resources using one of two purchasing models.
  • 無伺服器計算層中的單一資料庫具有多種可自動調整的計算資源,以及指定數量的每一核心記憶體,和指定數量的儲存體資源,且僅適用於以虛擬核心為基礎的購買模型A single database in the serverless compute tier has a range of compute resources that are auto-scaled plus a specified amount of memory per core, and a specified amount of storage resources and is only available in the vCore-based purchasing models.

當您建立單一資料庫時,您也會定義 SQL Database 伺服器加以管理,並將其放入指定區域中的 Azure 資源群組內。When you create a single database, you also define a SQL Database server to manage it and place it within Azure resource group in a specified region.

注意

本快速入門使用以虛擬核心為基礎的購買模型無伺服器計算層,但以 DTU 為基礎的購買模型也可供使用。This quickstart uses the vCore-based purchasing model and the serverless compute tier, but the DTU-based purchasing model is also available.

若要建立包含 AdventureWorksLT 範例資料的單一資料庫:To create a single database containing the AdventureWorksLT sample data:

  1. 選取 Azure 入口網站左上角的 [建立資源] 。Select Create a resource in the upper left-hand corner of the Azure portal.

  2. 選取 [資料庫] ,然後選取 [SQL Database] 以開啟 [建立 SQL Database] 頁面。Select Databases and then select SQL Database to open the Create SQL Database page.

    建立單一資料庫

  3. 在 [基本資料] 索引標籤的 [專案詳細資料] 區段中,輸入或選取下列值:On the Basics tab, in the Project Details section, type or select the following values:

    • 訂用帳戶 :下拉並選取正確的訂用帳戶 (若未出現)。Subscription: Drop down and select the correct subscription, if it doesn't appear.

    • 資源群組:選取 [新建] ,輸入 myResourceGroup,然後選取 [確定] 。Resource group: Select Create new, type myResourceGroup, and select OK.

      新的 SQL 資料庫 - 基本資料索引標籤

  4. 在 [資料庫詳細資料] 區段中,輸入或選取下列值:In the Database Details section, type or select the following values:

    • 資料庫名稱:輸入 mySampleDatabaseDatabase name: Enter mySampleDatabase.

    • 伺服器:選取 [新建] 並輸入下列值,然後選取 [選取] 。Server: Select Create new and enter the following values and then select Select.

      • 伺服器名稱mysqlserver類別;伴隨一些表示唯一性的數字。Server name: Type mysqlserver; along with some numbers for uniqueness.

      • 伺服器管理員登入:輸入 azureuserServer admin login: Type azureuser.

      • 密碼:輸入複雜密碼以符合密碼需求。Password: Type a complex password that meets password requirements.

      • 位置:從下拉式清單中選擇位置,例如 West US 2Location: Choose a location from the drop-down, such as West US 2.

        New server

      重要

      請記得記錄下伺服器管理員登入和密碼,以便在進行這個和其他快速入門時能夠登入伺服器和資料庫。Remember to record the server admin login and password so you can log in to the server and databases for this and other quickstarts. 如果您忘記登入或密碼,您可以在 [SQL Server] 頁面上取得登入名稱或重設密碼。If you forget your login or password, you can get the login name or reset the password on the SQL server page. 若要開啟 [SQL Server] 頁面,請在資料庫建立後,選取資料庫 [概觀] 頁面上的伺服器名稱。To open the SQL server page, select the server name on the database Overview page after database creation.

      SQL Database 詳細資料

    • 您要使用 SQL 彈性集區嗎:選取 [否] 選項。Want to use SQL elastic pool: Select the No option.

    • 計算 + 儲存體:選取 [設定資料庫] ,然後在本快速入門中,選取 [以虛擬核心為基礎的購買選項] Compute + storage: Select Configure database and for this quickstart, select vCore-based purchasing options

      以虛擬核心為基礎的購買選項

    • 選取 [無伺服器] 。Select Serverless.

      無伺服器計算層

    • 檢閱 [虛擬核心數上限] 、[虛擬核心數下限] 、[自動暫停延遲] 和 [資料大小上限] 的設定。Review the settings for Max vCores, Min vCores, Auto-pause delay, and Data max size. 視需要變更這些設定。Change these as desired.

    • 接受預覽條款,然後按一下 [確定] 。Accept the preview terms and click OK.

    • 選取 [套用] 。Select Apply.

  5. 選取 [其他設定] 索引標籤。Select the Additional settings tab.

  6. 在 [資料來源] 區段的 [使用現有資料] 下方,選取 SampleIn the Data source section, under Use existing data, select Sample.

    其他 SQL DB 設定

    重要

    請務必選取 [範例 (AdventureWorksLT)] 資料,以便依照本快速入門和使用這項資料的其他 Azure SQL Database 快速入門的指示操作。Make sure to select the Sample (AdventureWorksLT) data so you can follow easily this and other Azure SQL Database quickstarts that use this data.

  7. 將其餘的值保留為預設值,然後在表單底部選取 [檢閱 + 建立] 。Leave the rest of the values as default and select Review + Create at the bottom of the form.

  8. 檢閱最終設定,然後選取 [建立] 。Review the final settings and select Create.

  9. 在 [SQL Database] 表單中,選取 [建立] 以部署和佈建資源群組、伺服器和資料庫。On the SQL Database form, select Create to deploy and provision the resource group, server, and database.

查詢資料庫Query the database

您現在已建立資料庫,接著請使用 Azure 入口網站內建的查詢工具連線到資料庫,並查詢資料。Now that you've created the database, use the built-in query tool in the Azure portal to connect to the database and query the data.

  1. 在資料庫的 [SQL Database] 頁面上,選取左側功能表中的 [查詢編輯器 (預覽)] 。On the SQL Database page for your database, select Query editor (preview) in the left menu.

    登入查詢編輯器

  2. 輸入您的登入資訊,並選取 [確定] 。Enter your login information, and select OK.

  3. 在 [查詢編輯器] 窗格中輸入下列查詢。Enter the following query in the Query editor pane.

    SELECT TOP 20 pc.Name as CategoryName, p.name as ProductName
    FROM SalesLT.ProductCategory pc
    JOIN SalesLT.Product p
    ON pc.productcategoryid = p.productcategoryid;
    
  4. 選取 [執行] ,然後在 [結果] 窗格中檢閱查詢結果。Select Run, and then review the query results in the Results pane.

    查詢編輯器結果

  5. 關閉 [查詢編輯器] 頁面,並在系統提示是否要捨棄未儲存的編輯時選取 [確定] 。Close the Query editor page, and select OK when prompted to discard your unsaved edits.

清除資源Clean up resources

如果您想要繼續進行後續步驟,請保留此資源群組、資料庫伺服器和單一資料庫。Keep this resource group, database server, and single database if you want to go to the Next steps. 後續步驟會示範如何使用不同的方法連接及查詢您的資料庫。The next steps show you how to connect and query your database using different methods.

這些資源使用完畢後,您可以依照下列方式加以刪除:When you're finished using these resources, you can delete them as follows:

  1. 從 Azure 入口網站的左側功能表中,依序選取 [資源群組] 和 [myResourceGroup] 。From the left menu in the Azure portal, select Resource groups, and then select myResourceGroup.
  2. 在資源群組頁面上,選取 [刪除資源群組] 。On your resource group page, select Delete resource group.
  3. 在欄位中輸入 myResourceGroup ,然後選取 [刪除] 。Enter myResourceGroup in the field, and then select Delete.

後續步驟Next steps