• While shrinking each database in a production environment wouldn't be recommended, this does come in handy if you need to rein in your DBs on local or dev. Who here hasn’t had several runaway logs after some over eager developers were done with a particular server???

    This sets the backup point on the logs so they can be shrunk. It then returns both the log and data files to their original sizes if possible.

    DECLARE @cmd1 varchar(2000),

    @cmd2 varchar(2000)

    SET @cmd1 = 'BACKUP LOG [?] WITH NO_Log'

    SET @cmd2 = 'DBCC SHRINKDATABASE ([?],TRUNCATEONLY)'

    EXEC sp_msforeachdb @command1 = @cmd1,

    @command2 = @cmd2