giovedì 5 maggio 2011 #

SQL Server 2008: How To Shrink all files with one command

SQL Server 2008 has been eliminated NO_LOG BACKUP command that could be useful to truncate the log files of large size.

BACKUP LOG [DatabaseName] WITH NO_LOG

Many developers need to compress the testing databases files to avoid getting the disk space used unnecessarily. By executing the following you can shrink to a minimum all the log files of a database server:

EXECUTE sp_msforeachdb

'USE ?;

ALTER DATABASE ? SET RECOVERY SIMPLE;

DECLARE @LogLogicalName nvarchar(100);

SELECT @LogLogicalName = file_name(2);

DBCC SHRINKFILE(@LogLogicalName, 100);
ALTER DATABASE ? SET RECOVERY FULL;'

 

“sp_msforeachdb” is a no-documented stored procedure that runs the script for all the db in your server.
Use with caution!
Alberto.

posted @ giovedì 5 maggio 2011 9.39 | Feedback (2)

Copyright © Alberto De Luca

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski