TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Getting Size Of All Databases In SQL Server
Midhun Tp
Aug 11
2016
Code
753
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
SELECT
[
Database
Name
] = DB_NAME(database_id),
[Type] =
CASE
WHEN
Type_Desc =
'ROWS'
THEN
'Data File(s)'
WHEN
Type_Desc =
'LOG'
THEN
'Log File(s)'
ELSE
'Total Size'
END
,
[
Size
in
MB] =
CAST
( ((
SUM
(
Size
)* 8) / 1024.0)
AS
DECIMAL
(18,2))
FROM
sys.master_files
-- You can uncomment below condition, for getting details of specific database
-- WHERE database_id = DB_ID('YourDatabaseName')
GROUP
BY
GROUPING
SETS
(
(DB_NAME(database_id), Type_Desc),
(DB_NAME(database_id))
)
ORDER
BY
DB_NAME(database_id), Type_Desc
DESC
SQL