Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Shrink SQL Database

Posted on 2010-09-01
7
Medium Priority
?
436 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
[X]
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
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 27

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 27

Accepted Solution

by:
Chris Luttrell earned 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

604 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