Skip to content

Instantly share code, notes, and snippets.

View Soteark's full-sized avatar
💭
Coding

Cy Soteark

💭
Coding
View GitHub Profile
@Soteark
Soteark / DB_FileAllocationCheck.sql
Created May 29, 2023 03:56
Retrieves database files and their space sizes.
select
name [FileName]
,cast(size*1.0/128 as decimal(18,2)) [FileSizeinMB]
,cast(fileproperty(name,'SpaceUsed')/128 as decimal(18,2)) [SpaceUsedMB]
,cast(size/128.0 - cast(fileproperty(name,'SpaceUsed') as int)/128.0 as decimal(18,2)) [FreeSpaceMB]
,cast(cast(((cast(size as decimal(18,5)) - cast(fileproperty(name,'SpaceUsed') as decimal(18,5))) / size)*100 as decimal(18,2)) as varchar(10))+'%' [VolumeFree]
,'MaximumSizeinMB' =
case max_size
when 0 then 'No growth is allowed.'
when -1 then 'Autogrowth is on.'