Thursday, December 6, 2012

Shrink log for all databases

Below query helps to shrink transaction log for all databases

SELECT
      'USE [' + sd.name + N']' + CHAR(13) + CHAR(10)
    + 'DBCC SHRINKFILE (N''' + smf.name + N''' )'
    + CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10)
FROM
    sys.master_files smf
    JOIN sys.databases sd
        ON smf.database_id = sd.database_id WHERE smf.file_id=2
and sd.database_id > 4;
 

No comments: