You administer a SQL Server 2000 database named finance that stores customer account information. New account data is imported from branch offices at night by using a BULK INSERT statement. During the bulk load, employees report that response times for their queries become very slow. You want to ensure that loading new accounts does not significantly slow user response times. How should you modify the BULK INSERT operation?

Difficulty: Medium

Correct Answer: Add the BATCHSIZE option to the BULK INSERT statement and set it to a fraction (for example, 10 percent) of the total rows so that each batch commits separately.

Explanation:


Introduction / Context:
Bulk loading large volumes of data into SQL Server can place heavy demands on server resources and can block or slow down concurrent user activity. The BULK INSERT command supports options that influence locking behavior, transaction size and query optimizer decisions. This question focuses on how to adjust a bulk load so that user response times remain acceptable while still performing large imports of new account information.



Given Data / Assumptions:

  • The finance database contains a Customers table used by an online application.
  • New account data is loaded nightly using BULK INSERT.
  • During the bulk load, user queries become very slow.
  • The current BULK INSERT uses options such as DATAFILETYPE, FIELDTERMINATOR, ROWTERMINATOR and TABLOCK.
  • You want to minimize the effect on user response times.



Concept / Approach:
The BATCHSIZE option in BULK INSERT controls how many rows make up a single transaction. Each batch is committed separately, which can reduce the duration of locks and transaction log usage, thereby allowing other user transactions to interleave with the bulk load. In contrast, ROWS_PER_BATCH is primarily a hint to the optimizer about the expected number of rows and does not break the load into separate committed batches. Dropping and recreating indexes can speed up the bulk load but does not directly address concurrency during loading. Removing TABLOCK can even increase locking overhead because many smaller locks may be taken instead of a single bulk lock.



Step-by-Step Solution:
1. Analyze the current BULK INSERT command and determine the approximate number of rows in the input file. 2. Choose a reasonable batch size, for example 10 percent of the total number of rows, so that each batch is large enough to be efficient but not so large that it holds locks for too long. 3. Modify the BULK INSERT statement to include BATCHSIZE = N, where N is your chosen batch size. 4. When the command executes, SQL Server will break the input file into multiple batches, each committed separately. 5. Because locks are held only for the duration of each batch, user queries have more opportunities to run between batch commits, improving overall responsiveness.



Verification / Alternative check:
After implementing the BATCHSIZE option, monitor user response times and server metrics during the bulk load window. You should see shorter blocking periods and improved concurrency. You can also inspect the transaction log to confirm that it contains multiple smaller transactions rather than one very large one. If needed, you can further tune the batch size to strike a balance between bulk load throughput and user performance.



Why Other Options Are Wrong:
Option B, ROWS_PER_BATCH, is only a hint to the optimizer and does not actually break the load into separate transactions; it therefore does not significantly reduce lock duration or user blocking. Option C, dropping and recreating indexes, can make the load itself faster, but it can be disruptive and does not directly reduce contention during the load; moreover, recreating indexes also takes time and resources. Option D, removing TABLOCK, often increases lock overhead because SQL Server may acquire many row or page locks instead of a single more efficient bulk lock, and it does not by itself solve the blocking problem.



Common Pitfalls:
Administrators sometimes focus solely on making the bulk load as fast as possible and ignore the impact on concurrent users. Another pitfall is misunderstanding ROWS_PER_BATCH as a batching mechanism when it is not. Failing to tune transaction sizes can result in long-running transactions that hold locks and grow the log excessively, increasing the risk of blocking and even log full errors. Properly using BATCHSIZE gives you finer control over concurrency during bulk operations.



Final Answer:
You should add the BATCHSIZE option to the BULK INSERT statement and set it to a suitable fraction of the total rows so that the load occurs in multiple smaller transactions, reducing blocking and improving user response times.

More Questions from Microsoft Certification

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion