SELECT CASE WHEN (GROUPING(sob.name)=1) THEN 'All_Tables'
ELSE ISNULL(sob.name, 'unknown') END AS Table_name,
SUM(sys.length) AS Byte_Length
FROM sysobjects sob, syscolumns sys
WHERE sob.xtype='u' AND sys.id=sob.id
GROUP BY sob.name
WITH CUBE
Reference : Pinal Dave (https://blog.sqlauthority.com)
SQL SERVER – Query to Find ByteSize of All the Tables in Database
Pinal Dave is an SQL Server Performance Tuning Expert and independent consultant with over 22 years of hands-on experience. He holds a Masters of Science degree and numerous database certifications.
Pinal has authored 14 SQL Server database books and 90 Pluralsight courses. To freely share his knowledge and help others build their expertise, Pinal has also written more than 5,800 database tech articles on his blog at https://blog.sqlauthority.com.
Pinal is an experienced and dedicated professional with a deep commitment to flawless customer service. If you need help with any SQL Server Performance Tuning Issues, please feel free to reach out at pinal@sqlauthority.com.
Pinal is also a CrossFit Level 1 Trainer (CF-L1) and CrossFit Level 2 Trainer (CF-L2).
Nupur Dave is a social media enthusiast and an independent consultant. She primarily focuses on the database domain, helping clients build short and long-term multi-channel campaigns to drive leads for their sales pipeline.
Is your SQL Server running slow and you want to speed it up without sharing server credentials? In my Comprehensive Database Performance Health Check, we can work together remotely and resolve your biggest performance troublemakers in less than 4 hours.
Once you learn my business secrets, you will fix the majority of problems in the future.
Have you ever opened any PowerPoint deck when you face SQL Server Performance Tuning emergencies? SQL Server Performance Tuning Practical Workshop is my MOST popular training with no PowerPoint presentations and 100% practical demonstrations.
Essentially I share my business secrets to optimize SQL Server performance.
15 Comments. Leave new
how i can find? please reply
1.What is the current file system size of the database?
2. What is the current size of the tables (used)?
Good article Thank you :)
Simple & sweet!
great stuff…thanks
i am the beginner.. so may i know what is byte_length…
select a.name,Sum(b.[max_length]) from sys.objects a INNER JOIN
sys.columns b ON a.object_id=b.object_id Where type = ‘u’ Group by a.name
select a.name,Sum(b.[max_length]) from sys.objects a INNER JOIN
sys.columns b ON a.object_id=b.object_id Where type = ‘u’ Group by a.name
very helping article thanks buddy
Hi Pinal,
My table structure is like this.
using with above script am getting the Max_Length as “3”
Column_name Type Computed Length
ID int no 4
SPName varchar no -1
But varchar(max) length is 8000bytes …
How can we get exact lenght. Correct me if am wrong…
Regards,
abhIShek BandI
Nice thank you for such a nice information
Nice piece of information. As i am beginner as a DBA . I have started referring all your blogs from the beginning.
Select ISNULL(t.name,’AllTables’)[TableName],Sum(C.max_length)[TableSize]
from sys.tables T
join sys.columns C on t.object_id=C.object_id
Group by rollup (t.name)
Select ISNULL(t.name,’AllTables’)[TableName],Sum(C.max_length)[TableSize]
from sys.tables T
join sys.columns C on t.object_id=C.object_id
Group by Grouping Sets (t.name)
—-for DBs having compatablilty Mode less than 100 ;)
Good One.