What you will be able to do
- State the three conditions minimal logging always requires, and the recovery model it depends on.
- Navigate the index rules - when a clustered index or a non-empty table turns minimal logging back into full logging.
- Explain why a bulk load under FULL recovery can fill the log, and how bulk-logged recovery exists to answer that.
- Batch a large load so a failure does not force a rollback of the whole file.
Row-by-row INSERT is the wrong tool for a bulk load - it pays the full per-row log and lock cost
for millions of rows. SQL Server’s bulk path (BULK INSERT, bcp, OPENROWSET(BULK)) moves data
in extents rather than rows, and under the right conditions it barely logs at all. Getting those
conditions right is the difference between a load that finishes and one that fills the transaction
log and rolls back.
The analogy is a goods-in bay at a warehouse. Carrying stock through the front door box by box,
signing each item into the ledger, is row-by-row insert; reversing a lorry into the bay and tipping
whole pallets onto the floor is the bulk path, where the ledger just records the pallets that
landed rather than itemising every box. The bay doors stay locked to everyone else while the load
is in progress - the TABLOCK - and the summary paperwork is only permitted when the paperwork
rules allow it and the destination shelves are empty. Shelving into an aisle that already holds
stock forces the itemised log again, which is why the cheapest load lands on empty shelves.
The three conditions minimal logging always needs
Minimal logging is available only when all of these hold:
- Recovery model is SIMPLE or BULK_LOGGED - under FULL recovery every bulk row-insert is fully logged. This is the gate most loads trip on.
TABLOCKis specified - a table-level bulk-update lock on the load.- The table is not replicated and not memory-optimized - replication forces full logging even under BULK_LOGGED, because the log reader must reconstruct the rows.
When minimal logging applies, the engine logs extent allocations instead of every row - a small fraction of the log volume. It is also faster, not just smaller, because logging less is doing less.
The index rules - the part that surprises
Whether data and index pages are minimally logged depends on the table’s index state:
| Table shape | Data pages | Index pages |
|---|---|---|
| No indexes (heap) | Minimal | n/a |
| Heap + nonclustered indexes, empty | Minimal | Minimal (first batch; later batches log data only) |
| Heap + nonclustered indexes, non-empty | Minimal | Fully logged |
| Clustered index, empty | Minimal | Minimal |
| Clustered index, non-empty | Fully logged | Fully logged |
Any index with IGNORE_DUP_KEY = ON |
Fully logged | Fully logged |
The pattern that matters operationally: the cheapest bulk load is into an empty table with a clustered index, or into a heap and index afterward. Loading into a populated clustered table is fully logged regardless of recovery model - the table’s existing data is the reason. Loading in batches into an initially-empty clustered table keeps the first batch minimal and the later batches minimal on the data pages only.
A bulk load that stays fast and does not fill the log
Recovery + target
SIMPLE or BULK_LOGGED; empty clustered table or heap
FULL recovery makes every row fully logged - check before you start
TABLOCK load
BULK INSERT ... WITH (TABLOCK, BATCHSIZE = n)
BATCHSIZE splits the load so a failure rolls back a batch, not the file
Index afterward (heap case)
Rows in, then CREATE INDEX in one pass
Cheaper than maintaining the index through the load - one sort, not a million inserts
Verify + switch back
Row count, then FULL recovery if you moved to BULK_LOGGED
A log backup after returning to FULL restores the chain for point-in-time recovery
Why this is the right mental model
A fully-logged bulk load is not merely slow - it is a transaction-log hazard. Every row lands in the log, the log file grows until the disk is full or the operation aborts, and then the entire load rolls back (paying the log cost again in undo). The bulk-logged recovery model exists precisely for this: it temporarily replaces FULL during a large load so the load itself is minimally logged, while keeping the database in a recoverable state around it - with the documented caveat that a minimally-logged operation is only recoverable to the point of the last log backup, not point-in-time.
What to do about it
- Into a populated table you cannot empty - accept the full logging, use
BATCHSIZE, and watch log space, or stage into a heap andINSERT ... SELECTin batches. - The index-versus-load trade - for a large load into an empty heap, dropping nonclustered indexes first and rebuilding them after is almost always faster than maintaining them through the load; a single index build is one sort, maintenance is a per-row traversal.
- BATCHSIZE is your rollback boundary - set it so a failure rolls back one bounded batch rather than the whole file, and so each batch is a commit boundary that checkpoints can keep up with.
Guided practice
A beginner exercise, worked in a scratch database. The scenario: prove that the minimal-logging
conditions are real by watching log space across two loads - one that qualifies and one that does
not. DBCC SQLPERF(LOGSPACE) shows the log space your database is using. Work each step and check
yourself before moving on.
- Set the stage. Create a scratch database, set
RECOVERY SIMPLE, and create an empty heapdbo.stgwith a couple of columns. Note the database’s log space used fromDBCC SQLPERF(LOGSPACE). Check: recovery model isSIMPLEand the target is an empty heap - two of the conditions already met. If the database is underFULL, every row will be fully logged and the comparison below collapses; the recovery model is the gate most loads trip on. - Load with the conditions met. Run
INSERT INTO dbo.stg WITH (TABLOCK) SELECT ...pulling a few hundred thousand generated rows (cross-joining a numbers list is enough), then check log space again. Check: the log grew by a small amount - extent allocations were logged, not every row. If the growth tracked the data volume instead, find which condition failed;TABLOCKon the target is the usual omission. - Load against a disqualifying shape. Create a non-empty clustered table
dbo.stg_c, pre-load some rows, then run the sameINSERT ... WITH (TABLOCK) SELECTinto it and watch log space again. Check: log growth now tracks the row volume - a populated clustered table is fully logged regardless of recovery model. If it stayed small, the table was not both clustered and non-empty; revisit the index-state table - the table’s existing data is the reason. - Say why the cheapest shape is what it is. In one sentence each: why is loading into an empty
clustered table, or into a heap with the index built afterward, the cheapest bulk load?
Check: an empty clustered table keeps data and index pages minimally logged; a heap takes rows
minimally logged and then
CREATE INDEXis one sort rather than a per-row traversal through the load. If you answered “because heaps are faster”, revisit the index rules - the shape determines the logging, and logging less is doing less. - Bound the rollback. A real file load fails halfway. Which option keeps the failure from
rolling back the whole file, and what does it also give the checkpoints?
Check:
BATCHSIZE- each batch is a commit boundary, so a failure rolls back one bounded batch rather than the whole file, and checkpoints can keep up between batches. If you answeredTABLOCK, that unlocks the logging, not the rollback boundary; reread the load pipeline.
Check your understanding
Ordered easy to hard. Answer each before reading the answer; a wrong answer names where to look.
- What are the three conditions minimal logging always requires?
Recovery model
SIMPLEorBULK_LOGGED,TABLOCKspecified on the load, and a table that is neither replicated nor memory-optimized. All three must hold - the recovery model alone is the gate most loads trip on. Reread the conditions list if any was missing. - What does a minimally-logged load write to the transaction log instead of every row? Extent allocations - a small fraction of the log volume of per-row logging. It is faster as well as smaller, because logging less is doing less. If you answered “nothing”, that is the common misreading - minimal is not zero.
- Why is a fully-logged bulk load worse than merely slow?
Every row lands in the log, the log file grows until the disk fills or the operation aborts, and
the whole load then rolls back - paying the log cost again in undo. It is a transaction-log
hazard, not a slowdown; this is exactly why the
BULK_LOGGEDrecovery model exists. - Why does a populated clustered table defeat minimal logging even under
BULK_LOGGED? The index rules make a non-empty clustered table fully logged on both data and index pages - the table’s existing data is the reason, and no recovery model overrides it. The cheapest shapes are an empty clustered table, or a heap indexed afterward. If you expected recovery model to decide everything, revisit the index-state table. - Why does replication force full logging even when every other condition is met?
The log reader must reconstruct the rows for subscribers, and minimal logging writes only extent
allocations - there is nothing to reconstruct from. If you thought replication was just another
reader, revisit the third condition; it is the reason
TABLOCKandBULK_LOGGEDcannot rescue a replicated table.
Where SQL Server sits
How this component relates to the rest of the stack. Items without a link are not covered here yet.
Deployed with
Commonly run alongside
- Windows Failover Clustering