< Back
New-DbBulkCopy
Post
NAME New-DbBulkCopy
SYNOPSIS
Efficiently bulk loads data into a SQL Server table.
SYNTAX
New-DbBulkCopy [-InputObject] <Object> [[-Data] <Object>] [[-Options] {Default | KeepIdentity | CheckConstraints |
TableLock | KeepNulls | FireTriggers | UseInternalTransaction | AllowEncryptedValueModifications}] [[-Timeout]
<Object>] [-PassThru] [[-RetryCount] <Object>] [[-RetrySeconds] <Object>] [<CommonParameters>]
DESCRIPTION
Bulk loads data. Input columns do not need to be in the same order as the destination table as mapping is done.
PARAMETERS
-InputObject <Object>
A connection string, SqlConnection, SqlCommand, or SqlTransaction.
Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-Data <Object>
A DataSet or a DataTable (such as from Get-DbData).
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Options
A combination of special options from System.Data.SqlClient.SqlBulkCopyOptions.
Required? false
Position? 3
Default value Default
Accept pipeline input? false
Accept wildcard characters? false
-Timeout <Object>
Bulk copy timeout.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-PassThru [<SwitchParameter>]
Pass the input on in the pipeline for further operations.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-RetryCount <Object>
Required? false
Position? 5
Default value
Accept pipeline input? false
Accept wildcard characters? false
-RetrySeconds <Object>
Required? false
Position? 6
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
Pipe in the output of Get-DbData or similar.
OUTPUTS
(Optionally) Whatever was piped in.
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$serverInstance = ".\\SQL2016"
New-DbConnection $serverInstance | New-DbCommand "If Object_Id('dbo.Moo', 'U') Is Not Null Drop Table dbo.Moo;
Create Table dbo.Moo (A Int Identity (1, 1) Primary Key, B Nvarchar(Max)); Dbcc Checkident('dbo.Moo', Reseed,
100);" | Get-DbData -As NonQuery | Out-Null
$dbData = New-DbConnection $serverInstance | New-DbCommand "Select * From dbo.Moo;" | Get-DbData -As DataTables
-TableMapping @("Moo")
$dbData.Alter(@{ B = "A" }) | Out-Null
$dbData.Alter(@{ B = "B" }) | Out-Null
$dbData.Alter(@{ A = 100; B = "C" }) | Out-Null
$dbData.Alter(@{ B = "D" }) | Out-Null
New-DbConnection $serverInstance | New-DbCommand "Truncate Table dbo.Moo;" | Get-DbData -As NonQuery | Out-Null
New-DbConnection $serverInstance | New-DbBulkCopy -Data $dbData -Option "KeepIdentity"
New-DbConnection $serverInstance | New-DbCommand "Select * From dbo.Moo;" | Get-DbData
RELATED LINKS
SYNOPSIS
Efficiently bulk loads data into a SQL Server table.
SYNTAX
New-DbBulkCopy [-InputObject] <Object> [[-Data] <Object>] [[-Options] {Default | KeepIdentity | CheckConstraints |
TableLock | KeepNulls | FireTriggers | UseInternalTransaction | AllowEncryptedValueModifications}] [[-Timeout]
<Object>] [-PassThru] [[-RetryCount] <Object>] [[-RetrySeconds] <Object>] [<CommonParameters>]
DESCRIPTION
Bulk loads data. Input columns do not need to be in the same order as the destination table as mapping is done.
PARAMETERS
-InputObject <Object>
A connection string, SqlConnection, SqlCommand, or SqlTransaction.
Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-Data <Object>
A DataSet or a DataTable (such as from Get-DbData).
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Options
A combination of special options from System.Data.SqlClient.SqlBulkCopyOptions.
Required? false
Position? 3
Default value Default
Accept pipeline input? false
Accept wildcard characters? false
-Timeout <Object>
Bulk copy timeout.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-PassThru [<SwitchParameter>]
Pass the input on in the pipeline for further operations.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-RetryCount <Object>
Required? false
Position? 5
Default value
Accept pipeline input? false
Accept wildcard characters? false
-RetrySeconds <Object>
Required? false
Position? 6
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
Pipe in the output of Get-DbData or similar.
OUTPUTS
(Optionally) Whatever was piped in.
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$serverInstance = ".\\SQL2016"
New-DbConnection $serverInstance | New-DbCommand "If Object_Id('dbo.Moo', 'U') Is Not Null Drop Table dbo.Moo;
Create Table dbo.Moo (A Int Identity (1, 1) Primary Key, B Nvarchar(Max)); Dbcc Checkident('dbo.Moo', Reseed,
100);" | Get-DbData -As NonQuery | Out-Null
$dbData = New-DbConnection $serverInstance | New-DbCommand "Select * From dbo.Moo;" | Get-DbData -As DataTables
-TableMapping @("Moo")
$dbData.Alter(@{ B = "A" }) | Out-Null
$dbData.Alter(@{ B = "B" }) | Out-Null
$dbData.Alter(@{ A = 100; B = "C" }) | Out-Null
$dbData.Alter(@{ B = "D" }) | Out-Null
New-DbConnection $serverInstance | New-DbCommand "Truncate Table dbo.Moo;" | Get-DbData -As NonQuery | Out-Null
New-DbConnection $serverInstance | New-DbBulkCopy -Data $dbData -Option "KeepIdentity"
New-DbConnection $serverInstance | New-DbCommand "Select * From dbo.Moo;" | Get-DbData
RELATED LINKS