Skip to content

Instantly share code, notes, and snippets.

@gregjhogan
Last active April 26, 2017 01:30
Show Gist options
  • Select an option

  • Save gregjhogan/c1e1747ecb5a62c2cea00ccbcf0d7598 to your computer and use it in GitHub Desktop.

Select an option

Save gregjhogan/c1e1747ecb5a62c2cea00ccbcf0d7598 to your computer and use it in GitHub Desktop.
Shrink an Azure SQL database
DBCC SHRINKFILE ('data_0', TRUNCATE ONLY)
DBCC SHRINKFILE ('log', TRUNCATE ONLY)
-- view used/available space
SELECT
name,
CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 as SpaceUsedInMB,
size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 AS AvailableSpaceInMB
FROM sys.database_files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment