SqlBulkCopyOptions Enumeration
Bitwise flag that specifies one or more options to use with an instance of SqlBulkCopy.
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
Namespace: System.Data.SqlClientAssembly: System.Data (in System.Data.dll)
| Member name | Description | |
|---|---|---|
| Default | Use the default values for all options. | |
| KeepIdentity | Preserve source identity values. When not specified, identity values are assigned by the destination. | |
| CheckConstraints | Check constraints while data is being inserted. By default, constraints are not checked. | |
| TableLock | Obtain a bulk update lock for the duration of the bulk copy operation. When not specified, row locks are used. | |
| KeepNulls | Preserve null values in the destination table regardless of the settings for default values. When not specified, null values are replaced by default values where applicable. | |
| FireTriggers | When specified, cause the server to fire the insert triggers for the rows being inserted into the database. | |
| UseInternalTransaction | When specified, each batch of the bulk-copy operation will occur within a transaction. If you indicate this option and also provide a SqlTransaction object to the constructor, an ArgumentException occurs. |
You can use the SqlBulkCopyOptions enumeration when you construct a SqlBulkCopy instance to change how the WriteToServer methods for that instance behave.
The following console application demonstrates how to perform a bulk load that copies the value in the identity column of the source table to the corresponding column in the destination table, instead of generating a new value for each row's identity column.
To see how the option changes the way the bulk load works, run the sample with the dbo.BulkCopyDemoMatchingColumns table empty. All rows load from the source. Next, run the sample again without emptying the table. An exception is thrown, and the code writes a message to the console window notifying you that rows were not added because of primary key violations.
Important |
|---|
This sample will not run unless you have created the work tables as described in Bulk Copy Example Setup (ADO.NET). This code is provided to demonstrate the syntax for using SqlBulkCopy only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL INSERT … SELECT statement to copy the data. |
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Important