Solved

Shrink SQL Database

Posted on 2010-09-01
7
408 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Where not exists in same table 3 68
Divide by zero error encountered. 2 40
Unable to save view in SSMS 21 69
Query group by data in SQL Server - cursor? 3 32
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 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