Extended64
The 64-Bit Windows Community

Shrink SQL Server 2008 Database Log File Script

Here is a quick script to shrink the database log file in a SQL Server 2008 database.  This procedure has changed, since the BACKUP command does not work the same way as previous versions.  Replace DatabaseName with the name of your database, and LogFileName with logical name of your log file.

   1: Use DatabaseName 
   2: GO
   3: Alter Database DatabaseName Set Recovery Simple
   4: GO
   5: Alter Database DatabaseName Set Recovery Full
   6: GO
   7: DBCC SHRINKFILE ('LogFileName', 1)
   8: GO
   9: DBCC SHRINKFILE ('LogFileName', 1)
  10: GO
  11: DBCC SHRINKFILE ('LogFileName', 1)
  12: GO
  13: DBCC SHRINKFILE ('LogFileName', 1)
  14: GO
  15: DBCC SHRINKFILE ('LogFileName', 1)
  16: GO
  17: DBCC SHRINKFILE ('LogFileName', 1)
  18: GO

Posted Jun 11 2009, 03:44 AM by Ryan Hoffman

Comments

Twitted by tekmaven wrote Twitted by tekmaven
on 07-24-2009 3:21 AM

Pingback from  Twitted by tekmaven

SqlServerKudos wrote Shrink SQL Server 2008 Database Log File Script
on 07-26-2009 8:29 PM

Kudos for a great Sql Server article - Trackback from SqlServerKudos

Aaron Bertrand wrote Oh, the horror! Please stop telling people they should shrink their log files!
on 07-27-2009 11:52 AM

I realize that there are some cases where, in an emergency, you need to shrink a log file because it

Nick224422 wrote re: Shrink SQL Server 2008 Database Log File Script
on 01-12-2010 3:12 PM

Is this script in right order? shouldn't it be shrinked while its in simple recovery ....then back to Full ? I want to use it but just want to make sure first.

Please Sign in or Join to share your comments!
Copyright © Extended64.com, 2009. All rights reserved.