Question
How to query SQL database size?
Answer
In order to query SQL database size, please follow steps below:
Step 1
Run Microsoft SQL Server Management Studio, log in the to server you want to query
Step 2
Click New Query
Step 3
Use below codes:
with fs
as
(
select database_id, type, size * 8.0 / 1024 size
from sys.master_files
)
select
name,
(select sum(size) from fs where type = 0 and fs.database_id = db.database_id) DataFileSizeMB,
(select sum(size) from fs where type = 1 and fs.database_id = db.database_id) LogFileSizeMB
from sys.databases db
Step 4
Click Execute
Then you will see a list of data file size in MB.