使用 Azure SQL 数据库 构建和测试关系型及 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 资源管理器(ARM)模板,或者代理提示来创建免费层数据库。
使用 Azure 门户创建新的免费 Azure SQL 数据库。 要创建免费套餐数据库,请按照以下步骤操作:
转到 aka.ms/azuresqlhub 访问 Azure SQL 中心。
在“ 创建数据库”窗格中,选择“ 免费启动”。
在“基本信息”选项卡上:
- 在“项目详细信息”下:
- 选择订阅。 您当前的订阅已经被选择。
- 已选择现有 资源组 。 你可以选择不同的资源组,或者创建一个新的资源组。
- 在 “数据库详细信息”下:
- 使用自动生成的唯一 数据库名称,或提供新名称。
- 已选择现有的逻辑 服务器 。 你可以选择不同的逻辑服务器,或者创建一个新的逻辑服务器。
页面右侧的成本 汇总 卡显示的 预计成本/月 为零。 数据库以默认设置创建,包括当达到免费额度限制时暂停数据库的选项。 这些数据库设置可以稍后更改。
选择“查看 + 创建”。
查看并选择“ 创建”。
在活跃订阅中使用现有的逻辑服务器,或者创建一个新的。 此资源组必须已存在。 关于完整的服务器配置,请参见 创建单一数据库。
如果你需要一个新的逻辑服务器,请先创建一个:
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 对话助手,然后选择 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 输出中,
useFreeLimit 是 true.
- 每月免费额度的处理方式与你的选择相符。 本文中的创建示例使用
AutoPause;BillOverUsage 会启用付费超额用量。
使用 Azure 门户中的数据库的概述和计算 + 存储页面、az sql db show或Get-AzSqlDatabase来检查配置。
查询数据库
创建并验证数据库后,直接用你选择的工具或语言连接到该数据库。 运行语句前确认查询编辑器的目标数据库。
Important
教程中通用的 CREATE DATABASE 语句不会预配免费层数据库。 继续使用你通过免费套餐创建的数据库。 选择不需要其他数据库、恢复或导入的示例表说明。
监视和跟踪服务使用情况
跟踪免费使用情况
使用 Azure 门户跟踪剩余或已消耗的免费额度:
在数据库 概览 选项卡上,你会看到 每月免费 vCore 数量 条目。
选择“剩余的秒数”。 显示“指标”图表,在此可以查看“剩余的免费量”或“已消耗的免费量”指标。
在“指标”标签中,你也可以免费创建警报规则。 使用“剩余免费量”指标,当剩余量少于 10,000 vCore 秒(每月限额的 10%)时发送警报,就能知道当月的剩余量什么时候用完了。
使用数据库中心(预览版)监视
也可以选择使用 Microsoft Fabric 中的数据库中心(预览版),以获取你有权访问的 Azure SQL 数据库的整个资产范围视图。 它采用了 Fabric Free 许可证,不需要 Fabric 容量。 你的数据库仍然保留在现有的Azure订阅中。
关于设置和预览的前提条件,请参见“监控 Microsoft SQL 数据库”。 要添加性能数据,请参见启用 Microsoft SQL 的性能监控。
升级到 Hyperscale
随着工作负载的增加,你可以 将现有的免费套餐数据库升级到 Hyperscale。 指南涵盖了先决条件、分别用于禁用免费层和转换数据库的更新,以及验证。
允许付费超额并不会禁用免费套餐。 退出免费层对数据库而言是永久性的,而且即使后续的超大规模转换失败,付费的常规用途用量仍可能继续累积。 在做出更改前请先阅读升级指南。
注意事项和限制
以下考虑点和限制适用于 Azure SQL 数据库 免费套餐数据库:
- 免费套餐使用与付费数据库相同的全托管通用基础设施,但不包含服务水平协议(SLA)。 主要用于开发和概念验证场景。
- 当你达到每月免费使用上限时,选择行为:
-
在下个月开始前自动暂停数据库会停止计费,但在下个日历月开始、额度重置之前,数据库将无法访问。
-
继续使用数据库并支付额外费用会让数据库保持在线,并按标准通用型无服务器费率对超额使用部分计费。 你不能切回自动暂停选项。
- 免费套餐的数据库在15分钟无活动后会自动暂停。 自动暂停延迟是固定的,无论达到每月免费限额时选择的行为如何,都无法更改。
- 使用完毕后,请断开查询工具(例如 SQL Server Management Studio 和 Visual Studio Code 的 MSSQL 扩展)的连接,包括查询编辑器和对象资源管理器连接。 未关闭的连接会阻止空闲时自动暂停,并持续消耗 vCore 秒数。 断开连接并不会恢复已经消耗的使用量。 如果数据库不会自动暂停,请查看 阻止自动暂停的功能。
- 免费层级只能应用于新数据库。 你不能将现有数据库还原为免费层,或将其转换为免费层。
- 如果你使用 高级配置,第一个免费套餐数据库所选的区域会适用于该订阅中的所有免费套餐数据库,且无法更改。
关于备份、缩放、复制和功能兼容性的详细信息,请参见 Azure SQL 数据库免费层常见问题解答。
相关内容