BulkLoad
A BulkLoad
instance is used to perform a bulk insert.
Use connection.newBulkLoad to create a new instance,
and connection.execBulkLoad to execute it
(see usage section).
- Usage
- bulkLoad.addColumn(name, type, options)
- bulkLoad.getTableCreationSql()
- bulkLoad.setTimeout(timeout)
Usage
For more details on the ways the row data can be formatted, see connection.execBulkLoad.
-
checkConstraints
-
Honors constraints during bulk load, using T-SQL CHECK_CONSTRAINTS. (default:
false
) -
fireTriggers
-
Honors insert triggers during bulk load, using the T-SQL FIRE_TRIGGERS. (default:
false
) -
keepNulls
-
Honors null value passed, ignores the default values set on table, using T-SQL KEEP_NULLS. (default:
false
) -
tableLock
-
Places a bulk update(BU) lock on table while performing bulk load, using T-SQL TABLOCK. (default:
false
)
bulkLoad.addColumn(name, type, options)
Adds a column to the bulk load. The column definitions should match the table you are trying to insert into. Attempting to call addColumn after the first row has been added will throw an exception.
The name of the column.
One of the supported data types
.
Additional column type information. At a minimum, nullable
must be set to true or false.
nullable
indicates whether the column accepts NULL values.-
objName
If the name of the column is different from the name of the property found on row objects passed to , then you can use this option to specify the property name. length
for VarChar, NVarChar, VarBinary. Use length asInfinity
for VarChar(max), NVarChar(max) and VarBinary(max).precision
for Numeric, Decimalscale
for Numeric, Decimal, Time, DateTime2, DateTimeOffset
bulkLoad.getTableCreationSql()
This is simply a helper utility function which returns a CREATE TABLE
SQL statement based on the
columns added to the bulkLoad object. This may be particularly handy when you want to insert into a temporary
table (a table which starts with #
).
A side note on bulk inserting into temporary tables: if you want to access a local temporary table after executing the bulk load, you'll need to use the same connection and execute your requests using connection.execSqlBatch instead of .execSql.
bulkLoad.setTimeout(timeout)
Sets a timeout for this bulk load.
The number of milliseconds before the bulk load is considered failed, or 0 for no timeout.
When no timeout is set for the bulk load, the options.requestTimeout
of the Connection
is used.