DatawarehouseETLSQL Queries

How to create a Volume Data for Database

By 24/11/2022 October 8th, 2023 No Comments

Problem Statement:

This article describes how to display the data and log space information for a database in SQL Server by using SQL Server Management Studio or Transact-SQL.

Code Snippet:

-- Return volume stats for the drive(s) hosting database files
/* This script will display files used by Database, Disk Volume, Total and Available Space on Disk, Cussrent Size of Database files */
SELECT database_name, logical_filename,
s.volume_mount_point volume,
s.total_bytes volume_size,
s.available_bytes free_space,
f.size current_file_size
FROM sys.sysdatabases AS d
JOIN sys.master_files AS f ON d.dbid = f.database_id
CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.file_id) AS s;

Code Output:

Leave a Reply