适用于 Azure SQL 数据库的 Azure PowerShell 示例Azure PowerShell samples for Azure SQL Database

Azure SQL 数据库允许你使用 Azure PowerShell 配置数据库、实例和池。Azure SQL Database enables you to configure your databases, instances, and pools using Azure PowerShell.

如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

可以在本地安装并使用 PowerShell,本教程需要 AZ PowerShell 1.4.0 或更高版本。You can install and use the PowerShell locally, this tutorial requires AZ PowerShell 1.4.0 or later. 如果需要进行升级,请参阅 Install Azure PowerShell module(安装 Azure PowerShell 模块)。If you need to upgrade, see Install Azure PowerShell module. 如果在本地运行 PowerShell,则还需运行 Connect-AzAccount -Environment AzureChinaCloud 来创建与 Azure 的连接。If you are running PowerShell locally, you also need to run Connect-AzAccount -Environment AzureChinaCloud to create a connection with Azure.

单一数据库和弹性池Single Database and Elastic pools

下表包括了适用于 Azure SQL 数据库的示例 Azure PowerShell 脚本的链接。The following table includes links to sample Azure PowerShell scripts for Azure SQL Database.

创建和配置单一数据库和弹性池Create and configure single databases, and elastic pools
创建单一数据库和配置数据库服务器防火墙规则Create a single database and configure a database server firewall rule 此 PowerShell 脚本创建单一 Azure SQL 数据库,并配置服务器级防火墙规则。This PowerShell script creates a single Azure SQL database and configures a server-level firewall rule.
创建弹性池并移动入池数据库Create elastic pools and move pooled databases 此 PowerShell 脚本创建 Azure SQL 数据库弹性池,移动入池数据库并更改计算大小。This PowerShell script creates Azure SQL Database elastic pools, and moves pooled databases, and changes compute sizes.
配置异地复制和故障转移Configure geo-replication and failover
配置单一数据库并使用活动异地复制对其进行故障转移Configure and failover a single database using active geo-replication 此 PowerShell 脚本为单个 Azure SQL 数据库配置活动异地复制,并将其故障转移到次要副本。This PowerShell script configures active geo-replication for a single Azure SQL database and fails it over to the secondary replica.
配置入池数据库并使用活动异地复制对其进行故障转移Configure and failover a pooled database using active geo-replication 此 PowerShell 脚本为 SQL 弹性池中的 Azure SQL 数据库配置活动异地复制,并将其故障转移到次要副本。This PowerShell script configures active geo-replication for an Azure SQL database in a SQL elastic pool, and fails it over to the secondary replica.
针对单个数据库配置并故障转移一个故障转移组Configure and failover a failover group for a single database 此 PowerShell 脚本为 Azure SQL 数据库服务器实例配置故障转移组,将数据库添加到故障转移组,并将其故障转移到辅助服务器This PowerShell script configures a failover group for an Azure SQL Database server instance, adds a database to the failover group, and fails it over to the secondary server
缩放单一数据库和弹性池Scale a single database and an elastic pool
缩放单一数据库Scale a single database 此 PowerShell 脚本监视 Azure SQL 数据库的性能指标,将其缩放为更高的计算大小,并基于其中一个性能指标创建预警规则。This PowerShell script monitors the performance metrics of an Azure SQL database, scales it to a higher compute size and creates an alert rule on one of the performance metrics.
缩放弹性池Scale an elastic pool 此 PowerShell 脚本监视 Azure SQL 数据库弹性池的性能指标,将其缩放为更高的计算大小,并基于其中一个性能指标创建预警规则。This PowerShell script monitors the performance metrics of an Azure SQL Database elastic pool, scales it to a higher compute size, and creates an alert rule on one of the performance metrics.
审核和威胁检测Auditing and threat detection
配置审核和威胁检测Configure auditing and threat-detection 此 PowerShell 脚本为 Azure SQL 数据库配置审核和威胁检测策略。This PowerShell script configures auditing and threat detection policies for an Azure SQL database.
还原、复制和导入数据库Restore, copy, and import a database
还原数据库Restore a database 此 PowerShell 脚本从异地冗余备份还原 Azure SQL 数据库,并根据最新备份还原已删除的 Azure SQL 数据库。This PowerShell script restores an Azure SQL database from a geo-redundant backup and restores a deleted Azure SQL database to the latest backup.
将数据库复制到新服务器Copy a database to new server 此 PowerShell 脚本在新的 Azure SQL 服务器中创建现有 Azure SQL 数据库的副本。This PowerShell script creates a copy of an existing Azure SQL database in a new Azure SQL server.
从 bacpac 文件导入数据库Import a database from a bacpac file 此 PowerShell 脚本将数据库从 bacpac 文件导入到 Azure SQL 服务器。This PowerShell script imports a database to an Azure SQL server from a bacpac file.
在数据库之间同步数据Sync data between databases
在 SQL 数据库之间同步数据Sync data between SQL databases 此 PowerShell 脚本将数据同步配置为在多个 Azure SQL 数据库之间进行同步。This PowerShell script configures Data Sync to sync between multiple Azure SQL databases.
在 SQL 数据库和本地 SQL Server 之间同步数据Sync data between SQL Database and SQL Server on-premises 此 PowerShell 脚本将数据同步配置为在 Azure SQL 数据库和 SQL Server 本地数据库之间进行同步。This PowerShell script configures Data Sync to sync between an Azure SQL database and a SQL Server on-premises database.
更新 SQL 数据同步的同步架构Update the SQL Data Sync sync schema 此 PowerShell 脚本将在数据同步的同步架构中添加或删除项。This PowerShell script adds or removes items from the Data Sync sync schema.

详细了解单一数据库 Azure PowerShell APILearn more about the Single Database Azure PowerShell API.

其他资源Additional resources

此页上列出的示例使用 Azure SQL 数据库 cmdlet 来创建和管理 Azure SQL 资源。The examples listed on this page use the Azure SQL Database cmdlets for creating and managing Azure SQL resources. 用于运行查询和执行多个数据库任务的其他 cmdlet 位于 sqlserver 模块中。Additional cmdlets for running queries, and performing many database tasks are located in the sqlserver module. 有关详细信息,请参阅 SQL Server PowerShellFor more information, see SQL Server PowerShell.