Skip to content

Instantly share code, notes, and snippets.

@jsm85
Last active April 14, 2016 09:02
Show Gist options
  • Save jsm85/d7370d5c7354bd165f14 to your computer and use it in GitHub Desktop.
Save jsm85/d7370d5c7354bd165f14 to your computer and use it in GitHub Desktop.
Database Sizes and Truncate Scripts
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