-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathSqlBulkCopyOptions.xml
More file actions
86 lines (82 loc) · 5.55 KB
/
Copy pathSqlBulkCopyOptions.xml
File metadata and controls
86 lines (82 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<docs>
<members name="SqlBulkCopyOptions">
<SqlBulkCopyOptions>
<summary>
Bitwise flag that specifies one or more options to use with an instance of <see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />.
</summary>
<remarks>
You can use the <see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyOptions" /> enumeration when you construct a <see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" /> instance to change how the <see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(System.Data.Common.DbDataReader)" /> methods for that instance behave.
</remarks>
<example>
<format type="text/markdown">
<![CDATA[
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](https://learn.microsoft.com/sql/connect/ado-net/sql/bulk-copy-example-setup). 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.
[!code-csharp[SqlBulkCopy.KeepIdentity#1](~/../sqlclient/doc/samples/SqlBulkCopy_KeepIdentity.cs)]
]]>
</format>
</example>
</SqlBulkCopyOptions>
<AllowEncryptedValueModifications>
<summary>
<para>
When specified, <b>AllowEncryptedValueModifications</b> enables bulk copying of encrypted data between tables or databases, without decrypting the data. Typically, an application would select data from encrypted columns from one table without decrypting the data (the app would connect to the database with the column encryption setting keyword set to disabled) and then would use this option to bulk insert the data, which is still encrypted.
</para>
<para>
Use caution when specifying <b>AllowEncryptedValueModifications</b> as this may lead to corrupting the database because the driver does not check if the data is indeed encrypted, or if it is correctly encrypted using the same encryption type, algorithm and key as the target column.
</para>
</summary>
</AllowEncryptedValueModifications>
<CheckConstraints>
<summary>
Check constraints while data is being inserted. By default, constraints are not checked.
</summary>
</CheckConstraints>
<Default>
<summary>
Use the default values for all options.
</summary>
</Default>
<FireTriggers>
<summary>
When specified, cause the server to fire the insert triggers for the rows being inserted into the database.
</summary>
</FireTriggers>
<KeepIdentity>
<summary>
Preserve source identity values. When not specified, identity values are assigned by the destination.
</summary>
</KeepIdentity>
<KeepNulls>
<summary>
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.
</summary>
</KeepNulls>
<TableLock>
<summary>
Obtain a bulk update lock for the duration of the bulk copy operation. When not specified, row locks are used.
</summary>
</TableLock>
<UseInternalTransaction>
<summary>
When specified, each batch of the bulk-copy operation will occur within a transaction. If you indicate this option and also provide a <see cref="T:Microsoft.Data.SqlClient.SqlTransaction" /> object to the constructor, an <see cref="T:System.ArgumentException" /> occurs.
</summary>
</UseInternalTransaction>
<CacheMetadata>
<summary>
<para>
When specified, <b>CacheMetadata</b> caches destination table metadata after the first bulk copy operation, allowing subsequent operations to the same table to skip the metadata discovery query. This can improve performance when performing multiple bulk copy operations to the same destination table.
</para>
<para>
<b>Warning:</b> Use this option only when you are certain the destination table schema will not change between bulk copy operations. If the table schema changes (columns added, removed, or modified), using cached metadata may result in data corruption, failed operations, or unexpected behavior. Call <see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.InvalidateMetadataCache" /> to clear the cache if the schema changes.
</para>
<para>
The cache is automatically invalidated when <see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" /> is changed to a different table.
Changing <see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.ColumnMappings" /> between operations does not require cache invalidation because the cached metadata describes only the destination table schema, not the source-to-destination column mapping.
</para>
</summary>
</CacheMetadata>
</members>
</docs>