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 (http://blog.SQLAuthority.com)
SQL SERVER – Query to Find ByteSize of All the Tables in Database
November 10, 2006 by pinaldave
Posted in SQL, SQL Authority, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology | 13 Comments
13 Responses
Leave a Reply Cancel reply
Community Initiatives
About Pinal Dave
Pinal Dave is a Pluralsight Developer Evangelist. He has authored 9 SQL Server database books and have written over 2500 articles on the database technology on his blog at a http://blog.sqlauthority.com. Along with 9+ years of hands on experience he holds a Masters of Science degree and a number of certifications, including MCTS, MCDBA and MCAD (.NET). His past work experiences include Technology Evangelist at Microsoft and Sr. Consultant at SolidQ. Prior to joining Microsoft he was awarded the Microsoft MVP award for three continuous years for his contribution in the community. Here is the list of the Pinal Dave's books.
Follow @pinaldave
Send +Pinal Dave an email at pinal@sqlauthority.com-
- 63,186,045 (63 Million+)
SQL in Sixty Seconds
SQL Books
Funny Index Video
SQLAuthority Links
My Homepage
Windows Live Blog
--------------------
Top Downloads
PDF Downloads
Script Downloads
Script Bank
Favorite Scripts
All Scripts - 1
All Scripts - 2
All Scripts - 3
Top Articles
Best Articles
Favorite Articles - 1
Favorite Articles - 2
--------------------
> SQL Interview Q & A <
SQL Coding Standards
SQL FAQ Download
--------------------
Jobs @ SQLAuthority
About Nupur Dave
Nupur Dave loves technology simply because it makes life more convenient. She is devoted to technology because it touches our heart makes our daily lives easier. Among the many technological programs she uses and embraces Windows Live most because she can do lots of things with ease – from photo management to movies; business emails to personal social media connections.
Top 3 Commenters











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)?
@Sandhu
You can find it through two ways
a) Query Analyzer.
b) SSMS/Enterprise Manager.
a). Query Analyzer :
1. Sp_helpdb — execute this is master database.
Output : you will get information about all databases sizes.
2. sp_help ”database_name” —
Output: gives in detail information about Log and data file, with their sizes.
2. Sp_helpfile ( execute in the database for which you want size). Will give the same information about log and data file of the current database.
b) Enterprize manager: Expand Sql Server – Expand databases- click on database name = right click on database name – view – all task and then you can see in detail information about the size of the log file and also data file. And also you can see how much is filled, how much is empty.
b) in Enterprise Manager – right click database name , click properties, you will see the database size.
c) SSMS (2005) : Right click database select reports- click standard reports – Disk usage. you will see a report and you can see all details about sizes. If you expand the last point ” Disk usage by datafiles” you can see some good information.
d) SSMS (2005) – Right click database name, click properties and you can see database size.
To see the only logspace for all databases. Execute this statement,
DBCC SQLPERF( logspace)
Output: Will give you detail information about Logfile of the database.
your second question about tables:
Please visit this link : http://blog.sqlauthority.com/2008/07/08/sql-server-find-space-used-for-any-particular-table/
Hope this helps.
Thanks
Imran.
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
[...] Query to Find ByteSize of All the Tables in Database This was my second blog post and today I do not remember what was the business need which has made me build this query. It was built for SQL Server 2000 and it will not directly run on SQL Server 2005 or later version now. It measured the byte size of the tables in the database. This can be done in many different ways as well for example SP_HELPDB as well SP_HELP. I wish to build similar script in 2005 and later version. [...]
Nice piece of information. As i am beginner as a DBA . I have started referring all your blogs from the beginning.