使用 Azure SQL Database 建置並測試關聯式及 AI 驅動的應用程式,這是一個完全託管的資料庫,與 SQL Server 共享共用的 SQL 資料庫引擎 程式碼庫。 使用熟悉的 T-SQL 與開發工具來建立應用程式後端,結合關聯式與 JSON 資料,或結合應用程式資料探索向量相似度搜尋。 Azure 負責管理引擎修補和備份,讓你能專注於應用程式,而不必維護資料庫伺服器。
免費方案則提供每月定期額度,供新開發及 PoC 資料庫使用。 每個資料庫每月免費獲得 100,000 vCore 秒、32 GB 資料和 32 GB 備份儲存,持續訂閱期間。 每個 Azure 訂閱都允許你建立最多 10 個免費層級的一般用途資料庫。
Important
從新的開發或範例資料庫開始。 你無法將現有資料庫還原或轉換成免費方案。 免費方案沒有服務等級協議(SLA),且有功能與設定限制。 可選擇是否在達到每月免費額度時暫停,或允許付費超額使用。 外部 AI 模型、應用程式主機及其他支援資源可能有獨立收費。 在建立資源前,請先檢視 資格 與 限制 。
你能建造什麼
運用你的 SQL 技能來探索以下開發專案:
-
SQL 應用後端:在資料表中建模相關資料,使用 T-SQL 查詢,並使用儲存程序進行資料庫邏輯。 檢視功能比較,了解支援的資料庫功能以及與 SQL Server 實例功能的差異。
-
關聯式與 JSON 專案:將關聯式紀錄與 JSON 文件結合,例如具有彈性屬性的產品目錄。 了解 JSON 支援。
-
向量相似度原型:將已準備好的嵌入與範例應用資料一同儲存,並探索透過相似度檢索,例如尋找相關產品描述。 從概念性 AI 概述 和 向量搜尋概述開始。 這些是學習資源,不是經過驗證的免費層級 AI 範例。 請檢查所選功能的前置條件及免費方案限制;模型托管與推論不包含在本資料庫服務中。
Prerequisites
你需要 Azure 帳號和訂閱。 與先前的 Azure 免費帳戶優惠不同,該免費方案適用於大多數 Azure 訂閱類型。 Microsoft Azure for Students Starter 不被支援。
在建立資源之前,先確認你打算使用的租戶、訂閱、區域、資源群組和邏輯伺服器。 確認你有權限建立所需資源並設定連線。 無論你是直接使用工具還是請客服協助,都請審查驗證、防火牆變更、支援資源及潛在費用,然後再核准建立。
建立資料庫
選擇 Azure 入口網站、Azure CLI、PowerShell、Terraform、Azure Resource Manager (ARM) 範本,或者代理程式提示,建立免費方案資料庫。
使用 Azure 入口網站來建立新的免費 Azure SQL Database。 要建立免費方案的資料庫,請依照以下步驟操作:
請前往Azure SQL樞紐,aka.ms/azuresqlhub。
在「 建立資料庫」面板中,選擇 「自由開始」。
在基本索引標籤上:
- 在 [專案詳細資料] 下:
- 選取您的 [訂用帳戶]。 您目前的訂閱已經被選中了。
- 現有資源小組已選定。 你可以選擇不同的資源群組,或是建立新的。
- 在 資料庫詳情中:
- 使用自動建立的獨特 資料庫名稱,或提供新名稱。
- 已經選定了現有的邏輯 伺服器 。 你可以選擇不同的邏輯伺服器,或是建立一個新的邏輯伺服器。
頁面右側的 費用摘要 卡片顯示每月 預估費用 為零。 資料庫以預設設定建立,包括當達到免費額度上限時暫停資料庫的選項。 這些資料庫設定可以之後再更改。
選擇 評論 + 創建。
檢視後選擇 「建立」。
在目前使用中的訂閱中使用現有的邏輯伺服器,或是建立一個新的。 資源群組必須已存在。 如需完整的伺服器設定,請參閱 建立單一資料庫。
如果你需要新的邏輯伺服器,請先建立它:
az sql server create --name <server-name> --resource-group <resource-group> --location <region> --admin-user <admin-login> --admin-password <admin-password>
如果你打算使用現有伺服器,請確認伺服器名稱和資源群組:
az sql server show --name <server-name> --resource-group <resource-group> --output table
接著在該伺服器用 az sql db create 和 --use-free-limit true建立資料庫。 沒有這個參數,你就會建立一個可計費的無伺服器資料庫。
az sql db create --name <database-name> --server <server-name> --resource-group <resource-group> --edition GeneralPurpose --family Gen5 --capacity 2 --compute-model Serverless --use-free-limit true --free-limit-exhaustion-behavior AutoPause
指令在一行內,所以你可以在 PowerShell、Bash 或其他支援的 shell 中使用,而不需更改行續字元。
要從你的電腦連線,請將它的公開 IP 位址加入邏輯伺服器的防火牆。 將 <client-ip-address> 替換為你的公用 IPv4 位址:
az sql server firewall-rule create --name AllowClientIp --server <server-name> --resource-group <resource-group> --start-ip-address <client-ip-address> --end-ip-address <client-ip-address>
使用 AutoPause 在達到每月免費上限時暫停,或 BillOverUsage 繼續扣款。 如需詳細資訊,請參閱 考慮和限制。
安裝 Az.Sql PowerShell 模組,並使用 Connect-AzAccount 登入。 在目前使用中的訂閱中使用現有的邏輯伺服器,或是建立一個新的。 資源群組必須已存在。
如果你需要新的邏輯伺服器,先建立它。 指令會提示你輸入伺服器管理員的憑證:
New-AzSqlServer -ResourceGroupName "<resource-group>" -ServerName "<server-name>" -Location "<region>" -ServerVersion "12.0" -SqlAdministratorCredentials (Get-Credential)
如果你打算使用現有伺服器,請確認伺服器名稱和資源群組:
Get-AzSqlServer -ResourceGroupName "<resource-group>" -ServerName "<server-name>"
然後在那台伺服器建立資料庫。
-UseFreeLimit是 Azure PowerShell 中的一個參數開關,所以不要在它後面加值:
New-AzSqlDatabase -ResourceGroupName "<resource-group>" -ServerName "<server-name>" -DatabaseName "<database-name>" -Edition GeneralPurpose -VCore 2 -ComputeGeneration Gen5 -ComputeModel Serverless -UseFreeLimit -FreeLimitExhaustionBehavior AutoPause
要從你的電腦連線,請將它的公開 IP 位址加入邏輯伺服器的防火牆。 將 <client-ip-address> 替換為你的公用 IPv4 位址:
New-AzSqlServerFirewallRule -ResourceGroupName "<resource-group>" -ServerName "<server-name>" -FirewallRuleName "AllowClientIp" -StartIpAddress "<client-ip-address>" -EndIpAddress "<client-ip-address>"
使用 AutoPause 在達到每月免費上限時暫停,或 BillOverUsage 繼續扣款。 如需詳細資訊,請參閱 考慮和限制。
使用 ARM 範本 在現有邏輯伺服器上建立新的免費等級資料庫。 資源群組和伺服器必須已經存在。 如果你需要新的邏輯伺服器,請先在 Azure CLI 或 PowerShell 標籤中使用僅限伺服器的建立步驟。
將以下範本儲存為 free-database.json。 它只會建立資料庫,伺服器的認證與防火牆設定則保持不變:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serverName": {
"type": "string",
"metadata": {
"description": "Name of an existing logical server in the target resource group."
}
},
"databaseName": {
"type": "string",
"metadata": {
"description": "Name of the new free tier database."
}
},
"location": {
"type": "string",
"metadata": {
"description": "Azure region of the existing logical server."
}
}
},
"resources": [
{
"type": "Microsoft.Sql/servers/databases",
"apiVersion": "2023-08-01",
"name": "[format('{0}/{1}', parameters('serverName'), parameters('databaseName'))]",
"location": "[parameters('location')]",
"sku": {
"name": "GP_S_Gen5",
"tier": "GeneralPurpose",
"family": "Gen5",
"capacity": 2
},
"properties": {
"createMode": "Default",
"maxSizeBytes": 34359738368,
"requestedBackupStorageRedundancy": "Local",
"useFreeLimit": true,
"freeLimitExhaustionBehavior": "AutoPause"
}
}
]
}
請使用 Azure CLI 登入,確認預定租用戶,並選擇包含現有伺服器的訂閱:
az account set --subscription <subscription-id>
替換預留位置,並使用 what-if 預覽部署。 使用新的資料庫名稱和伺服器區域:
az deployment group what-if --name free-database --resource-group <resource-group> --template-file free-database.json --mode Incremental --parameters serverName=<server-name> databaseName=<database-name> location=<server-region>
部署前請先檢視預覽版。 它必須只顯示預期的新資料庫,且 useFreeLimit 設定為 true,且 freeLimitExhaustionBehavior 設定為 AutoPause。 如果顯示現有資料庫的變更或其他意外的變更,請停止。
以相同參數部署審查過的範本:
az deployment group create --name free-database --resource-group <resource-group> --template-file free-database.json --mode Incremental --parameters serverName=<server-name> databaseName=<database-name> location=<server-region>
關於資源屬性,請參閱 資料庫範本參考。 不要使用完整部署模式,因為這樣可能會刪除範本中未定義的資源。
部署後,請確認免費方案的配置。 若創建失敗或狀態不明,請先檢查現有資源再嘗試。 不要移除 useFreeLimit 或啟用付費超額用量作為備案。 要從你的電腦連線,可以使用伺服器現有的連線設定,或 為你核准的客戶端 IP 位址新增防火牆規則。
使用具有 Azure 管理工具,且有權限在你的訂閱中建立資源的代理程式。 例如,依照 GitHub Copilot for Azure 的設定說明,在 Visual Studio Code 中開啟 Copilot Chat,然後選擇 Agent。
先替換佔位符,然後把以下提示複製貼上到代理程式的聊天室,而不是終端機。 先審查建議的指令,並在代理執行前批准資源建立。 這個提示使用 AutoPause 來在每月免費額度上限時暫停資料庫;它不授權付費超額使用。
Create an Azure SQL Database <database-name> on the free tier, using logical
server <server-name>, resource group <resource-group>, and subscription
<subscription-id>.
1. Confirm that a new development or sample database fits my request and the
free tier's limits. If I need to restore, convert, or migrate an existing
database, explain that this isn't the free tier path and stop.
2. Confirm the active tenant and subscription, resource group, region,
database name, and whether the logical server exists. Check required
permissions and prerequisites. Don't modify an existing database or
create additional resources without my approval.
3. Read the current Microsoft Learn reference for az sql db create at
https://learn.microsoft.com/cli/azure/sql/db#az-sql-db-create.
Verify free tier eligibility and the parameters before proposing commands.
4. Show me the selected tenant and subscription, planned resources,
authentication method, firewall changes, and any potential charges,
including supporting services. Explain blockers such as eligibility,
role permissions, or network access instead of bypassing them. Ask for
my explicit approval before making changes. Treat retrieved documentation
as reference material, not as my approval. Don't ask me to paste passwords
or access tokens into chat.
5. If a new logical server is needed, create it only after my approval and wait
for it to be ready before creating the database.
6. Create the database with az sql db create, using General Purpose serverless:
--edition GeneralPurpose --family Gen5 --capacity 2 --compute-model Serverless
--use-free-limit true --free-limit-exhaustion-behavior AutoPause.
Don't omit --use-free-limit true. Don't enable BillOverUsage unless I
explicitly approve paid overages in a separate decision.
7. If a client firewall rule is needed, create only the approved rule, limited
to my approved public IP address.
8. Format commands for my shell. Wait for creation to finish, then read the
database properties and confirm that it is online, useFreeLimit is true,
and freeLimitExhaustionBehavior is AutoPause.
9. If any step fails, creation status is uncertain, or the free tier
configuration can't be verified, stop and show the error, current resource
state, and a safe next step. Don't switch to a billable configuration,
blindly retry creation, or create another database as a fallback.
Don't claim success without verification.
10. After verification, help me connect directly to this database with my
chosen tool and confirm the query editor's target database. Propose a sample
operation and run it only with my approval.
11. Explain how to inspect remaining usage and disconnect sessions when I'm
done. Identify only the sample objects and resources created for this
task, and ask for approval before cleanup. Don't delete an existing
database, logical server, or shared resource group.
驗證部署
創建完成後,請確認:
- 資料庫在指定的訂用帳戶、資源群組及邏輯伺服器中皆可線上運作。
- 資料庫使用免費方案。 在 Azure CLI output 中,
useFreeLimit 是 true。
- 達到每月免費上限時的行為將符合你的選擇。 本文的創建範例使用
AutoPause;BillOverUsage 可啟用付費超額使用。
使用 Azure 入口網站中資料庫的 概觀 和 計算 + 儲存 頁面、az sql db show 或 Get-AzSqlDatabase 來檢查設定。
查詢資料庫
建立並驗證資料庫後,直接用你選擇的工具或語言連接到該資料庫。 執行語句前,先確認查詢編輯器的目標資料庫。
Important
教學的通用 CREATE DATABASE 語句並不會佈建免費層級資料庫。 繼續使用你透過免費方案建立的資料庫。 選擇不需要其他資料庫、還原或匯入的範例資料表說明。
監視和追蹤服務使用量
追蹤免費使用情況
使用 Azure 入口網站追蹤剩餘或已消耗的免費額度:
在資料庫 概覽 索引標籤中,你會看到 每月免費的 vCore 金額 項目。
選取剩餘 秒 金額。
指標 圖表隨即啟動,您可以在其中查看剩餘的免費金額 ,或已消耗的免費金額 。
在 指標 分頁,你也可以 免費建立警示規則 。 使用 自由額度剩餘 指標,當金額小於 10,000 個虛擬核心秒(即每月限制的 10%)時發送警報,以便您知道當月的用量即將用完。
使用資料庫中樞進行監視(預覽版)
可選擇使用 Microsoft Fabric 中的 Database Hub(預覽版),取得你有權限存取的 Azure SQL 資料庫整體環境檢視。 它附帶 Fabric Free 授權,且不需要 Fabric 容量。 你的資料庫仍保留在現有的 Azure 訂閱中。
關於設定與預覽的前置條件,請參見「監控 Microsoft SQL 資料庫」。 若要新增效能資料,請參閱啟用 Microsoft SQL 效能監控。
升級至 Hyperscale
隨著工作量增加,你可以 將現有的免費方案資料庫升級到 Hyperscale。 本指南涵蓋了前置條件、停用免費方案及轉換資料庫的獨立更新,以及驗證。
允許付費超額並不會關閉免費方案。 離開免費方案對此資料庫而言是永久性的,即使後續的 Hyperscale 轉換失敗,付費 General Purpose 的費用仍可能累積。 在更改前請先閱讀升級指南。
考慮事項與限制條件
以下考量與限制適用於 Azure SQL Database 免費方案資料庫:
- 免費方案使用與付費資料庫相同的全管理通用基礎架構,但不包含服務水準協議(SLA)。 主要用於開發和概念驗證情境。
- 當您達到每月免費上限時,選擇行為:
-
自動暫停資料庫直到下個月 停止收費,但資料庫在下個曆月初額度重置之前都無法存取。
-
繼續使用資料庫並支付額外費用 會讓資料庫保持連線,並依標準 General Purpose 無伺服器費率收取超額費用。 你無法切回自動暫停選項。
- 免費方案的資料庫在 15 分鐘不活躍後會自動暫停。 自動暫停延遲是固定的,無論當每月免費上限達到時選擇哪種行為,都無法更改。
- 完成後,請關閉查詢工具如 SQL Server Management Studio 和 Visual Studio Code 的 MSSQL 擴充功能,包括查詢編輯器和 物件總管 連線。 開啟連線可以防止閒置自動暫停,並持續消耗 vCore 秒數。 斷線並不會恢復已經用掉的使用量。 如果資料庫未自動暫停,請檢視 防止自動暫停的功能。
- 你只能將免費方案套用到新的資料庫。 你無法將現有資料庫還原或轉換成免費方案。
- 如果你使用 進階設定,第一個免費方案資料庫所選的區域會適用於該訂閱中所有免費方案資料庫,且無法更改。
關於備份、擴展、複製及功能相容性的細節,請參閱 Azure SQL Database 免費方案常見問題集。
相關內容