Last active
December 21, 2015 22:58
-
-
Save jbubriski/6378749 to your computer and use it in GitHub Desktop.
A SQL Server script to generate the Shrink commands for all the databases in an instance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE #f | |
GO | |
CREATE TABLE #f (name sysname, fileid int, filename sysname, filegroup sysname null, | |
size sysname, maxsize sysname, growth sysname, usage sysname) | |
GO | |
EXEC sp_MSforeachdb 'DECLARE @s VARCHAR(8000); | |
USE [?]; | |
TRUNCATE TABLE #f; | |
INSERT #f (name, fileid, filename, filegroup, size, maxsize, growth, usage ) | |
EXEC sp_helpfile | |
SELECT @s = ''use [?]; DBCC SHRINKFILE ('''''' + name + '''''')'' | |
FROM #f | |
WHERE usage = ''log only'' | |
AND ''?'' NOT IN (''master'', ''tempdb'', ''model'', ''msdb'') | |
PRINT @s' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment