Last active
April 14, 2016 09:02
-
-
Save jsm85/d7370d5c7354bd165f14 to your computer and use it in GitHub Desktop.
Database Sizes and Truncate Scripts
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
select | |
sd.dbid as DatabaseID, | |
sd.[name] as DatabaseName, | |
sd.crdate as CreationDate, | |
saf.[name] as DatabaseFile, | |
saf.[filename] as DatabaseFileLocation, | |
(saf.[size] * 8 / 1024) as [Size], | |
'USE MASTER BACKUP LOG ' + sd.[name] + ' WITH TRUNCATE_ONLY | |
GO USE ' + sd.[name] + ' DBCC SHRINKFILE(' + saf.[name] + ',100) | |
GO' as TruncateLog_Sql2008, | |
'USE ' + sd.[name] + ' ' + | |
'GO' + ' ' + | |
'DBCC SHRINKFILE (' + sd.[name] + ')' as TruncateLog_Sql2012 | |
from | |
master..sysdatabases sd | |
inner join | |
master..sysaltfiles saf on sd.dbid = saf.dbid | |
order by Size desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment