Accounting for Transaction Log Growth

When I copy two columns—approximately 5MB in disk size and containing fewer than 400,000 rows—from one table to another, the copying process seems to enlarge the transaction log by about 100MB, even when I drop the indexes from the destination table. I use the following statement to copy the data:

INSERT into Table_A (Col1, Col2)
SELECT Col1, Col2 FROM Table_B

The database is set up to truncate on checkpoint, and autoshrink is turned on. Is it typical for this INSERT statement to cause the transaction log to increase by such a large amount, and if so, what can I do to reduce the log's size?

Based on the information you provided, you can account for about 60MB of log space for your operation. Each row in the INSERT CASE claims about 56 bytes of log-record overhead. So, assuming that each data record uses 12 bytes, each insert would occupy about 70 bytes of log space. Multiply 70 by 400,000 records, then multiply the product (28 million bytes) by 2 to account for the compensation log record's reserved space. So far, the byte consumption amounts to 56MB. But wait—you aren't finished. SQL Server has to allocate about 650 pages to perform the insert, so you can tack on an additional couple of megabytes. The rest of the bloat could be due to the log file's original size. If the table contains a clustered index, the amount of space would increase again because of splitting index pages.

To keep your inserts from increasing the transaction log file so much, execute the inserts in smaller transactions based on an ordering key. And to reduce the log's size, you can also run one of the shrink log space scripts (i.e., DBCC SHRINKFILE and DBCC SHRINKDATABASE) that are available from the Microsoft Developer Network (MSDN) Web site at http://msdn.microsoft.com.

Discuss this Article 1

Anonymous User (not verified)
on Mar 2, 2005
My transaction log for a DB has exceeded 37GB, the nature of our DB is not so senstive so I dont see a need to keep it at all, as to my understanding it only holds transaction history among tables. Can I just simply get rid of it by deleting it? How can deleting the transaction log affect my DB?

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Michael Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 21, 2013
blog

A Common Misconception about MAXDOP

Out of the box, SQL Server is (and has been) able to take advantage of multiple processors/cores without any effort on behalf of administrators....More
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.