Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Shrink SQL Database

Posted on 2010-09-01
7
414 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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