Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Total Space Used Per Table
WhatsApp
Arun Kumar
Jul 26
2016
578
0
0
SELECT
SCHEMA_NAME(o.schema_id) +
'.'
+ OBJECT_NAME(p.object_id)
AS
NAME
,
SUM
(reserved_page_count) * 8
AS
total_space_used_kb,
SUM
(
CASE
WHEN
index_id < 2
THEN
reserved_page_count
ELSE
0
END
) * 8
AS
table_space_used_kb,
SUM
(
CASE
WHEN
index_id > 1
THEN
reserved_page_count
ELSE
0
END
) * 8
AS
nonclustered_index_spaced_used_kb,
MAX
(row_count)
AS
row_count
FROM
sys.dm_db_partition_stats
AS
p
INNER
JOIN
sys.all_objects
AS
o
ON
p.object_id = o.object_id
WHERE
o.is_ms_shipped = 0
GROUP
BY
SCHEMA_NAME(o.schema_id) +
'.'
+ OBJECT_NAME(p.object_id)
ORDER
BY
NAME
select
B.
name
,
CONVERT
(
numeric
(30,3),(
CONVERT
(
float
,
SUM
(A.used_page_count)*8)/1024))
as
[
Table
Used
Size
(MB)],
CONVERT
(
numeric
(30,3),(
CONVERT
(
float
,
SUM
(A.reserved_page_count)*8)/1024))
as
[
Table
Located
Size
(MB)],
(
CONVERT
(
numeric
(30,3),(
CONVERT
(
float
,
SUM
(A.reserved_page_count)*8)/1024)) -
CONVERT
(
numeric
(30,3),(
CONVERT
(
float
,
SUM
(A.used_page_count)*8)/1024)))
as
[
Table
Free
Size
(MB)] ,
A.row_count
from
sys.dm_db_partition_stats
as
A, sys.all_objects
as
B
where
A.object_id = B.object_id
and
B.type !=
'S'
group
by
name
,row_count
order
by
B.
name
asc
Space Per Table
SQL Server
Up Next
Total Space Used Per Table