Поделиться через


Read-SqlViewData

Reads data from a view of a SQL database.

Синтаксис

ByPath (по умолчанию)

Read-SqlViewData
    [[-Path] <String[]>]
    [-TopN <Int64>]
    [-ColumnName <String[]>]
    [-ColumnOrder <String[]>]
    [-ColumnOrderType <OrderType[]>]
    [-OutputAs <OutputTypeSingleTable>]
    [-AccessToken <PSObject>]
    [-TrustServerCertificate]
    [-HostNameInCertificate <String>]
    [-Encrypt <String>]
    [<CommonParameters>]

ByName

Read-SqlViewData
    [[-ServerInstance] <String[]>]
    [-ViewName <String>]
    [-TopN <Int64>]
    [-ColumnName <String[]>]
    [-ColumnOrder <String[]>]
    [-ColumnOrderType <OrderType[]>]
    [-OutputAs <OutputTypeSingleTable>]
    [-DatabaseName <String>]
    [-SchemaName <String>]
    [-IgnoreProviderContext]
    [-SuppressProviderContextWarning]
    [-Credential <PSCredential>]
    [-ConnectionTimeout <Int32>]
    [-AccessToken <PSObject>]
    [-TrustServerCertificate]
    [-HostNameInCertificate <String>]
    [-Encrypt <String>]
    [<CommonParameters>]

ByObject

Read-SqlViewData
    [-InputObject] <ScriptSchemaObjectBase[]>
    [-TopN <Int64>]
    [-ColumnName <String[]>]
    [-ColumnOrder <String[]>]
    [-ColumnOrderType <OrderType[]>]
    [-OutputAs <OutputTypeSingleTable>]
    [-AccessToken <PSObject>]
    [-TrustServerCertificate]
    [-HostNameInCertificate <String>]
    [-Encrypt <String>]
    [<CommonParameters>]

Описание

The Read-SqlViewData cmdlet reads data stored in a view of a SQL database. You can select which columns to read, limit the number of rows, and sort and order columns.

You can use this cmdlet with the Windows PowerShell SQL provider. This cmdlet can infer information such as server, database, schema, and table from its current path.

This cmdlet supports the follow output formats:

  • DataSet. An object of type System.Data.DataSet that contains one table.
  • DataTable. An object of type System.Data.DataTable. The TableName property of this object is the same as the table that this cmdlet queries.
  • DataRows. A collection of System.Data.DateRow objects.

Примеры

Example 1: Get two rows from a view

PS C:\> Read-SqlViewData -ServerInstance "MyServer\MyInstance" -DatabaseName "MyDatabase" -SchemaName "dbo" -ViewName "MyView" -TopN 2

Id Name   Amount
-- ----   ------
10 AAAAA  -1.2
11 BBBBB  1.2

This command gets the first two rows from the database view MyDatabase.dbo.MyView on the MyServer\MyInstance instance. The TopN parameter specifies the number of rows (2 in this case).

Example 2: Display a whole view

PS C:\> cd SQLSERVER:\sql\MyServer\MyInstance\Databases\MyDatabase\Views\dbo.MyView
PS SQLSERVER:\sql\MyServer\MyInstance\Databases\MyDatabase\Views\dbo.MyView> Read-SqlViewData

Id Name Amount
-- ---- ------
10 AAAA -1.2
11 BBBB 1.2
12 CCCC -1.0
13 DDDD -2.0

The first command changes the location to be a view in the SQLSERVER provider. The command prompt reflects the new location.

Example 3: Display selected sorted columns

PS C:\> cd SQLSERVER:\sql\MyServer\MyInstance\Databases\MyDatabase\Views\dbo.MyView
PS SQLSERVER:\sql\MyServer\MyInstance\Databases\MyDatabase\Views\dbo.MyView> Read-SqlViewData -TopN 3 -ColumnName "Id","Name" -ColumnOrder "Id","Name" -ColumnOrderType DESC,ASC

Id Name
-- ----
12 CCCC
11 BBBB
10 AAAA

Параметры

-AccessToken

The access token used to authenticate to SQL Server, as an alternative to user/password or Windows Authentication.

This can be used, for example, to connect to SQL Azure DB and SQL Azure Managed Instance using a Service Principal or a Managed Identity.

The parameter to use can be either a string representing the token or a PSAccessToken object as returned by running Get-AzAccessToken -ResourceUrl https://database.windows.net.

This parameter is new in v22 of the module.

Свойства параметра

Тип:PSObject
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-ColumnName

Specifies an array of names of columns that this cmdlet returns.

Свойства параметра

Тип:

String[]

Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False
Aliases:ColumnToReturn

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-ColumnOrder

Specifies an array of names of columns by which this cmdlet sorts the columns that it returns.

Свойства параметра

Тип:

String[]

Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False
Aliases:OrderBy

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-ColumnOrderType

Specifies an array of order types for columns that this cmdlet returns. The acceptable values for this parameter are:

  • ASC. Ascending.
  • DESC. Descending.

The values that you specify for this parameter match the columns that you specify in the ColumnOrder parameter. This cmdlet ignores any extra values.

Свойства параметра

Тип:

OrderType[]

Default value:None
Допустимые значения:ASC, DESC
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-ConnectionTimeout

Specifies the number of seconds to wait for a server connection before a time-out failure. The time-out value must be an integer between 0 and 65534. If 0 is specified, connection attempts do not time out.

Свойства параметра

Тип:Int32
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

ByName
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-Credential

Specifies a PSCredential object for the connection to SQL Server. To obtain a credential object, use the Get-Credential cmdlet. For more information, type Get-Help Get-Credential.

Свойства параметра

Тип:PSCredential
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

ByName
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-DatabaseName

Specifies the name of the database that contains the view.

If you run this cmdlet in the context of a database or a child item of a database, the cmdlet ignores this parameter value. Specify the IgnoreProviderContext parameter for the cmdlet to use the value of the DatabaseName parameter anyway.

Свойства параметра

Тип:String
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

ByName
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-Encrypt

The encryption type to use when connecting to SQL Server.

This value maps to the Encrypt property SqlConnectionEncryptOption on the SqlConnection object of the Microsoft.Data.SqlClient driver.

In v22 of the module, the default is Optional (for compatibility with v21). In v23+ of the module, the default value will be 'Mandatory', which may create a breaking change for existing scripts.

This parameter is new in v22 of the module.

Свойства параметра

Тип:String
Default value:None
Допустимые значения:Mandatory, Optional, Strict
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-HostNameInCertificate

The host name to be used in validating the SQL Server TLS/SSL certificate. You must pass this parameter if your SQL Server instance is enabled for Force Encryption and you want to connect to an instance using hostname/shortname. If this parameter is omitted then passing the Fully Qualified Domain Name (FQDN) to -ServerInstance is necessary to connect to a SQL Server instance enabled for Force Encryption.

This parameter is new in v22 of the module.

Свойства параметра

Тип:String
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-IgnoreProviderContext

Indicates that this cmdlet does not use the current context to override the values of the ServerInstance, DatabaseName, SchemaName, and ViewName parameters. If you do not specify this parameter, the cmdlet ignores the values of these parameters, if possible, in favor of the context in which you run the cmdlet.

Свойства параметра

Тип:SwitchParameter
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

ByName
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-InputObject

Specifies an array of SQL Server Management Objects (SMO) objects that represent the view that this cmdlet reads.

Свойства параметра

Тип:

ScriptSchemaObjectBase[]

Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

ByObject
Position:1
Обязательно:True
Значение из конвейера:True
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-OutputAs

Specifies the type of output.

Свойства параметра

Тип:OutputTypeSingleTable
Default value:None
Допустимые значения:DataSet, DataTable, DataRows
Поддерживаются подстановочные знаки:False
DontShow:False
Aliases:As

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-Path

Specifies the path of the view that this cmdlet reads.

Свойства параметра

Тип:

String[]

Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

ByPath
Position:1
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-SchemaName

Specifies the name of the schema for the table.

If you run this cmdlet in the context of a database or a child item of a database, the cmdlet ignores this parameter value. Specify the IgnoreProviderContext parameter for the cmdlet to use the value of the SchemaName parameter anyway.

Свойства параметра

Тип:String
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

ByName
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-ServerInstance

Specifies the name of an instance of SQL Server. For the default instance, specify the computer name. For named instances, use the format ComputerName\InstanceName.

If you run this cmdlet in the context of a database or a child item of a database, the cmdlet ignores this parameter value. Specify the IgnoreProviderContext parameter for the cmdlet to use the value of the ServerInstance parameter anyway.

Свойства параметра

Тип:

String[]

Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

ByName
Position:1
Обязательно:False
Значение из конвейера:True
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-SuppressProviderContextWarning

Indicates that this cmdlet suppresses the warning message that states that the cmdlet uses the provider context.

Свойства параметра

Тип:SwitchParameter
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

ByName
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-TopN

Specifies the number of rows of data that this cmdlet returns. If you do not specify this parameter, the cmdlet returns all the rows.

Свойства параметра

Тип:Int64
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False
Aliases:First

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-TrustServerCertificate

Indicates whether the channel will be encrypted while bypassing walking the certificate chain to validate trust.

In v22 of the module, the default is $true (for compatibility with v21). In v23+ of the module, the default value will be '$false', which may create a breaking change for existing scripts.

This parameter is new in v22 of the module.

Свойства параметра

Тип:SwitchParameter
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-ViewName

Specifies the name of the view from which this cmdlet reads.

If you run this cmdlet in the context of a database or a child item of a database, the cmdlet ignores this parameter value. Specify the IgnoreProviderContext parameter for the cmdlet to use the value of the ViewName parameter anyway.

Свойства параметра

Тип:String
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False
Aliases:Name

Наборы параметров

ByName
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Входные данные

System.String