# Friday, July 08, 2011

Shrink SQL Server 2008 R2 log files

I just discovered that if you run SQL Server on your developer box and never bother to cleanup your log files, then perhaps they get to be a little big Smile.
Here is a script to quickly shrink a log file:
 
 
Use [YourDatabaseName]
Go
 
select name,recovery_model_desc from sys.databases
GO 
Alter database [YourDatabaseName] SET RECOVERY SIMPLE
GO
Declare @LogFileLogicalName sysname
select @LogFileLogicalName=Name from sys.database_files where Type=1
print @LogFileLogicalName
 
DBCC Shrinkfile(@LogFileLogicalName,100) 
#    Comments [1] |