Solved

Shrink SQL Database

Posted on 2010-09-01
7
391 Views
Last Modified: 2012-05-10
I have made a copy of an SQL database.  the reason for the copy is to experiment with queries and stored procedures.  It is not uncommon to empty and fill up a table with 70,000 records many times a day while I am experimenting.
How can I drop the Transaction log.  I have found as the Transaction log gets large the speed of the database slows.  I assume the log grows because of my large deletes queries and inserting queries.

Is it correct that if I make a backup of the database that SQL will truncate the tranaction log file, but it will not shrink the size of the log on the harddrive?
0
Comment
Question by:dastaub
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 7

Expert Comment

by:rcombis
ID: 33583250
Here are some steps that should be helpful for you.

http://www.codeproject.com/KB/database/truncate_log_SQL_server.aspx

0
 
LVL 3

Expert Comment

by:omnimaven
ID: 33583253
You can change the recovery model of your database to simple recovery model.

You can also force SQL Server to truncate the log by:

 backup log <your database name> with tuncate_only
0
 
LVL 3

Expert Comment

by:omnimaven
ID: 33583264
After executing the command:

backup log <your database name> with tuncate_only

You can manually shrink the file by:

dbcc shrinkfile (<the log file name>, <resulting file size>)
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 26

Expert Comment

by:Chris Luttrell
ID: 33583426
You are right that it is you mass inserts and updates that are filling up the transaction log.
Another thing you can do is temporarily change the recovery model while doing them.
In this example my database is CGL, replace that with your database name.

USE [master]
GO
ALTER DATABASE [CGL] SET RECOVERY BULK_LOGGED
GO

USE [CGL]
GO

-- Do your mass inserts or updates here


USE [master]
GO
ALTER DATABASE [CGL] SET RECOVERY FULL WITH NO_WAIT
GO
0
 

Author Comment

by:dastaub
ID: 33583522
Is there an advantage to truncate the transaction Log but not shrink the log file size.  This will prevent SQL from having to manage increasing the size of the log file.
0
 
LVL 26

Accepted Solution

by:
Chris Luttrell earned 500 total points
ID: 33583558
yes, if you truncate it but do not shrink, it will not have to reallocate the space as it grows again.  That would be an advantage in your case if you are continually doing this in a test environment.  
Another thought, if it is really just a test environment can you not just set the recovery model to simple and not have to mess with the log at all?
0
 

Author Closing Comment

by:dastaub
ID: 33583623
Thank you.  Gave you a complete answer.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now