patternsqlModerate
How large are blocks of data in SQL Server?
Viewed 0 times
blocksaresqllargehowserverdata
Problem
I'm working in SQL Server 2008 R2 and have created a query that gathers and sums the total of data files and log files' sizes. However, I can't find how much actual disk space a single block of SQL data takes up on the disk so I can convert it into something more meaningful.
Here is the script:
How large is one block of space? Would it be easy to convert those two integer variables into something more meaningful for a sysadmin?
Here is the script:
DECLARE @DataSize INT
DECLARE @LogSize INT
SELECT @DataSize = SUM(size) from sys.database_files where type_desc = 'Rows'
SELECT @LogSize = SUM(size) from sys.database_files where type_desc = 'Log'
PRINT @DataSize
PRINT @LogSizeHow large is one block of space? Would it be easy to convert those two integer variables into something more meaningful for a sysadmin?
Solution
From the column documentation of
size: Current size of the file, in 8-KB pages.
So a more meaningful query might be something like this:
(You can expand on that further as necessary.)
sys.database_files:size: Current size of the file, in 8-KB pages.
So a more meaningful query might be something like this:
SELECT
df.name AS LogicalFileName,
df.physical_name AS PhysicalPath,
CONVERT(int, (((df.size * 8192) / 1024.0) / 1024.0)) AS SizeInMB
FROM sys.database_files df;(You can expand on that further as necessary.)
Code Snippets
SELECT
df.name AS LogicalFileName,
df.physical_name AS PhysicalPath,
CONVERT(int, (((df.size * 8192) / 1024.0) / 1024.0)) AS SizeInMB
FROM sys.database_files df;Context
StackExchange Database Administrators Q#46022, answer score: 14
Revisions (0)
No revisions yet.