Skip to content

Instantly share code, notes, and snippets.

@chrismckelt
Created July 24, 2018 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismckelt/a35bca1428a1e7560cdef030ef9862c4 to your computer and use it in GitHub Desktop.
Save chrismckelt/a35bca1428a1e7560cdef030ef9862c4 to your computer and use it in GitHub Desktop.
sql shrink databases
SELECT
'USE [' + d.name + N']' + CHAR(13) + CHAR(10)
+ 'DBCC SHRINKFILE (N''' + mf.name + N''' , 0, TRUNCATEONLY)'
+ CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10)
FROM
sys.master_files mf
JOIN sys.databases d
ON mf.database_id = d.database_id
WHERE d.database_id > 4;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment