SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Shrinking log files
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

10Dawg
Starting Member

USA
46 Posts

Posted - 02/21/2013 :  11:42:45  Show Profile  Reply with Quote
Sql 2008
Below is what I use to shrink log files. With this code, I have to name each db therefore I am constantly updating it. Is there a way to say shrink all user defined log files?

USE Exxxxxxxxx;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE Exxxxxxxxx
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 GB.
DBCC SHRINKFILE (Exxxxxxxxx_log, 0);
GO
ALTER DATABASE Exxxxxxxxx
SET RECOVERY FULL;
GO

James K
Flowing Fount of Yak Knowledge

3760 Posts

Posted - 02/21/2013 :  12:33:42  Show Profile  Reply with Quote
You can find the names of all the log files using this query:
SELECT * FROM sys.master_files  WHERE type_Desc = 'LOG'
Once you have that, you can construct the SQL needed to shrink the files.

BUT, before you do any of that, please read this article by Paul Randal. http://www.sqlskills.com/blogs/paul/why-you-should-not-shrink-your-data-files/ I realize that there are occasions when one needs to shrink the log files such as after one-time operations that may have caused the log file to grow. But, shrinking log file routinely is very counter productive.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000