Download presentation
Presentation is loading. Please wait.
1
Bulk Load and Minimal Logging
Dean Savović Bulk Load and Minimal Logging
2
Sponsors
3
Agenda Minimal Logging Defined Minimal Logging Cross Reference
Enhancements Methods Delete Update
4
Minimal Logging Defined
Only full page BU Locking Batchsize Enable/disable triggers and constraints Input sort order (clustered target)
5
Minimal Logging Prereqs
Simple or Bulk-logged recovery model TABLOCK (not always) Target table not replicated ALLOW_PAGE_LOCKS „ON” Backup
6
Minimally Logged Operations
Bulk import operations (BCP, BULK INSERT and INSERT..SELECT) SELECT INTO operations TRUNCATE Starting in Sql server 2008 , INSERT SELECT statement can also be handled with minimal logging. Partial updates to large value data types, using the .WRITE clause. CREATE INDEX, ALTER INDEX REBUILD DROP TABLE Partition Switch Merge
7
Bulk Methods Integration Services Data Destinations BCP BULK INSERT
SQL Server Destination OLE DB Destination BCP BULK INSERT INSERT … SELECT SELECT … INTO …
8
Minimal Logging Heap IsEmpty TABLOCK Locks Logging Concurrent Yes
BU-Tab Minimal No IX-Tab Full
9
Data – minimal index – full
Minimal Logging Heap + Non-Clustered Index IsEmpty TABLOCK Locks Logging Concurrent Yes Sch-M Minimal No IX-Tab Full Data – minimal index – full
10
Minimal Logging Clustered Index IsEmpty TABLOCK Locks Logging
Concurrent Yes Sch-M Minimal No IX-Tab X-Tab Full
11
Minimal Logging Clustered Index + Non-Clustered Index IsEmpty TABLOCK
Locks Logging Concurrent Yes Sch-M Depends No IX-Tab
12
Minimal Logging Columnstore Index 102400 NO TABLOCK
13
Minimal Logging Memory Optimized Always Fully Logged
14
Bulk Load Enhancements
Select * Into dbo.TargetTable from dbo.SourceTable (SQL Server 2005-) Insert into dbo.TargetTable with (TABLOCK) select * from dbo.SourceTable (SQL Server 2008+) Insert into CI Btree (SQL Server 2008+) Order by Enable TF-610 Bulk insert (SQL Server 2008+) Without TABLOCK
15
Insert Scenarios
16
Comparison bulk insert dbo.tTable from 'd:\temp\tHeap.csv’ with ( formatfile = ‘D:\temp\bcp.fmt’ , rows_per_batch = )
17
Heap No Indexes
18
Heap and Indexes
19
Clustered
20
Clustered And Non-Clus Indexes
21
Memory Optimized
22
Columnstore (CCI)
23
Comparison
24
Deleting a Large Amount of Rows in a Partition or Table in Minimally Logging Mode
25
Create a Copy of Main Table
26
Bulk load the rows you want to keep into the temporary partition
INSERT INTO Sales_Temp WITH (TABLOCK) SELECT * FROM Sales WHERE OrderDate >=‘ ’ AND OrderDate <‘ ’ AND<Keep Criteria>
27
Switch out and truncate the old data
28
Rebuild indexes and use SWITCH
ALTER TABLE Sales_Temp TO Sales SWITCH PARTITION 1
29
Drop the temporary table
30
Updating a Large Part of the Data in a Partition or a Table in Minimally Logged Mode
31
Write a change log to a temporary table
32
If the table is partitioned, switch out the partition you want to change
ALTER TABLE Sales SWITCH PARTITION 1 TO Sales_Old
33
Merge the change log with the original table and bulk load to temporary table
SELECT o.PrimaryKey ,COALESCE(d.Col1, o.Col1) , COALESCE(d.Col2, o.Col3) ... etc... FROM Sales_Old o LEFT JOIN Sales_Delta d
34
Delete the change log and original data
DROP TABLE Sales_Delta DROP TABLE Sales_Old
35
SWITCH in the result of the merge
ALTER TABLE Sales_New SWITCH TO Sales PARTITION 1 DROP TABLE Sales_New
36
EXEC [sys]. [sp_tableoption] @TableNamePattern = N'dbo
EXEC [sys].[sp_tableoption] @TableNamePattern = N'dbo.BulkLoadTest’, @OptionName = 'table lock on bulk load’, @OptionValue = 'ON'
37
Evaluations Event Evaluation Session Evaluation
Session Evaluation
38
Sponsors
39
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.