你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Get-AzureSqlDatabase

检索一个或多个数据库。

注意

本文档中引用的 cmdlet 用于管理使用 Azure Service Manager (ASM) API 的旧式 Azure 资源。 创建新资源时,建议不要使用旧的 PowerShell 模块,因为计划将停用 ASM。 有关详细信息,请参阅 Azure Service Manager 停用

Az PowerShell 模块是建议用于管理 PowerShell 的 Azure 资源管理器 (ARM) 资源的 PowerShell 模块。

语法

Get-AzureSqlDatabase
   -ConnectionContext <IServerDataServiceContext>
   [-Database <Database>]
   [-DatabaseName <String>]
   [-RestorableDropped]
   [-RestorableDroppedDatabase <RestorableDroppedDatabase>]
   [-DatabaseDeletionDate <DateTime>]
   [-Profile <AzureSMProfile>]
   [<CommonParameters>]
Get-AzureSqlDatabase
   -ServerName <String>
   [-Database <Database>]
   [-DatabaseName <String>]
   [-RestorableDropped]
   [-RestorableDroppedDatabase <RestorableDroppedDatabase>]
   [-DatabaseDeletionDate <DateTime>]
   [-Profile <AzureSMProfile>]
   [<CommonParameters>]

说明

Get-AzureSqlDatabase cmdlet 从Azure SQL 数据库服务器检索Azure SQL 数据库的一个或多个实例。 可以使用使用 New-AzureSqlDatabaseServerContext cmdlet 创建的Azure SQL 数据库服务器连接上下文来指定服务器。 或者,如果指定Azure SQL 数据库服务器名称,cmdlet 将使用当前的 Azure 订阅信息对访问服务器的请求进行身份验证。

如果未指定数据库, Get-AzureSqlDatabase cmdlet 将从指定服务器返回所有数据库。

检索可还原的已删除数据库:

使用 RestorableDropped 参数检索可还原的已删除数据库。 若要返回所有可还原的已删除数据库,请使用没有 DatabaseNameDatabaseDeletionDate 的 RestorableDropped 参数。 若要返回特定的可还原已删除数据库,请使用具有 DatabaseNameDatabaseDeletionDate 参数的 RestorableDropped 参数。 使用 DatabaseName 参数检索特定可还原的已删除数据库时,还必须包含 DatabaseDeletionDate 参数,并且指定的 DatabaseDeletionDate 值必须包含毫秒才能与所需数据库匹配。

Get-AzureSqlDatabase cmdlet 返回服务器上所有可还原的已删除数据库,或一个与 DatabaseNameDatabaseDeletionDate 匹配的特定数据库。 若要返回满足不同条件的可还原已删除数据库(例如特定名称的所有可还原的已删除数据库),必须返回所有可还原的已删除数据库,然后在客户端上筛选结果。

示例

示例 1:检索服务器上的所有数据库

PS C:\> Get-AzureSqlDatabase -ServerName "lpqd0zbr8y"

此命令检索名为 lpqd0zbr8y 的服务器中的所有数据库。

示例 2:检索服务器上所有可还原的已删除数据库

PS C:\> Get-AzureSqlDatabase -ServerName "lpqd0zbr8y" -RestorableDropped

此命令检索名为 lpqd0zbr8y 的服务器上所有可还原的已删除数据库。

示例 3:从连接上下文指定的服务器检索数据库

PS C:\> $Database01 = Get-AzureSqlDatabase -ConnectionContext $Context -DatabaseName "Database01"

此命令从连接上下文$Context指定的服务器中检索名为 Database01 的数据库。

示例 4:将数据库对象存储在变量中

PS C:\> $Database01 = Get-AzureSqlDatabase -ServerName "lpqd0zbr8y" -DatabaseName "Database01"

此命令从名为 lpqd0zbr8y 的服务器检索名为 Database01 的数据库。 该命令将数据库对象存储在 $Database 01 变量中。

示例 5:检索可还原的已删除数据库

PS C:\> $DroppedDB = Get-AzureSqlDatabase -ServerName "lpqd0zbr8y" -DatabaseName "Database01" -DatabaseDeletionDate "2012-11-09T22:59:43.000Z" -RestorableDropped

此命令从名为 lpqd0zbr8y 的服务器检索在 2012/11/9/2012 中删除的可还原已删除的数据库 Database01。 此命令将结果存储在$DroppedDB变量中。

示例 6:检索服务器上所有可还原的已删除数据库并筛选结果

PS C:\> Get-AzureSqlDatabase -ServerName "lpqd0zbr8y" -RestorableDropped | Where-Object {$_.Name -eq "ContactDB"}

此命令检索名为 lpqd0zbr8y 的服务器上所有可还原的已删除数据库,然后将结果筛选为仅名为 ContactDB 的数据库。

参数

-ConnectionContext

指定要从中检索数据库的服务器的连接上下文。

类型:IServerDataServiceContext
别名:Context
Position:Named
默认值:None
必需:True
接受管道输入:True
接受通配符:False

-Database

指定一个对象,该对象表示此 cmdlet 检索的数据库。

类型:Database
Position:Named
默认值:None
必需:False
接受管道输入:True
接受通配符:False

-DatabaseDeletionDate

指定删除的日期和时间。 如果指定 RestorableDropped 参数,请指定此参数以基于删除日期和时间检索可还原的已删除数据库。

DatabaseDeletionDate 参数必须包含毫秒才能匹配所需数据库的时间。 指定一个不带毫秒的值会导致找不到数据库。

类型:DateTime
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-DatabaseName

指定此 cmdlet 检索的数据库的名称。

类型:String
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Profile

指定此 cmdlet 从中读取的 Azure 配置文件。 如果未指定配置文件,此 cmdlet 将从本地默认配置文件中读取。

类型:AzureSMProfile
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-RestorableDropped

指示此 cmdlet 返回 RestorableDroppedDatabase 对象而不是 Database 对象。 可以使用 DatabaseDeletionDate 参数选择特定的可还原已删除数据库。

类型:SwitchParameter
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-RestorableDroppedDatabase

指定一个对象,该对象表示此 cmdlet 检索的可还原的已删除数据库。

类型:RestorableDroppedDatabase
Position:Named
默认值:None
必需:False
接受管道输入:True
接受通配符:False

-ServerName

指定包含此 cmdlet 检索的数据库的服务器的名称。 该 cmdlet 使用当前的 Azure 订阅来访问服务器。

类型:String
Position:Named
默认值:None
必需:True
接受管道输入:True
接受通配符:False

输入

Microsoft.WindowsAzure.Commands.SqlDatabase.Services.Server.Database

Microsoft.WindowsAzure.Commands.SqlDatabase.Services.Server.RestorableDroppedDatabase

输出

IEnumerable\<Microsoft.WindowsAzure.Commands.SqlDatabase.Services.Server.Database\>

如果未指定 RestorableDropped 参数,此 cmdlet 将返回 Database 对象。

IEnumerable\<Microsoft.WindowsAzure.Commands.SqlDatabase.Services.Server.RestorableDroppedDatabase\>

如果指定 RestorableDropped 参数,此 cmdlet 将返回 RestorableDroppedDatabase 对象。