Saturday, October 12, 2013
Truncate logs on all databases with recovery mode of simple
declare @tblSqlCode dbo.ExecSqlStatementsTableType
insert into @tblSqlCode(SqlCode)
SELECT
'use ' + d.name + ';' + CHAR(10)
+ 'Checkpoint;' + CHAR(10)
+ 'DBCC SHRINKFILE([' + mf.name + ']);' + CHAR(10)
FROM
[sys].[databases] d
JOIN [sys].[master_files] mf
ON d.database_id = mf.database_id
WHERE
d.recovery_model = 3 -- simple
AND d.[state] = 0 -- online
AND mf.state = 0 -- online
AND mf.type = 1 -- log
AND d.is_read_only = 0
AND d.name NOT IN ('master', 'tempdb', 'model', 'msdb')
--SELECT * FROM @tblSqlCode
exec dbo.usp_ExecSqlStatements @TableSqlCode=@tblSqlCode, @UseTransactions=0
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment