Finding the biggest tables in a database

By Bill Graziano on 4 August 2000 | 4 Comments | Tags: Storage/Sizing


This quick article includes a discussion on SQL Server tools to determine the size of tables in a database. It also has a downloadable script I wrote to find the largest tables in a database.

In one of my projects, I'm working with a piece of packaged software. This software has roughly 700 tables in it. We spent about two weeks installing the database and configuring it. As part of this process we loaded numerous "lookup" tables. We finished with a 2.5GB database. This was before we had loaded a single record or converted any data from our existing system. Uh oh.

So I set out trying to find out where all this data was. I started with Enterprise Manager. If you select the name of a database, the right hand pane will show an information screen about that database. The second "tab" lists tables and index sizes. Unfortunately they were in alphabetical order. After I scrolled through the first hundred or so I gave up.

Next I turned to sp_spaceused. This is a nifty little stored procedure that will tell you how big your datbase is. If you give it the name of a table as a parameter it will display the size of that table. If you need to know the size of a specific table this is a great little utility. It still wasn't what I was looking for but it was close.

One nice feature about SQL Server is the source code for system stored procedures, such as sp_spaceused, is readily available. It is just a stored procedure in the master database that can be opened and viewed just like any other stored procedure.

So I took this code and modfied it for my needs. BigTables.sql will run through your database and display information about your 25 largest tables. It's pretty easy to change the number of tables displayed. You could also turn this into a parameterized stored procedure if you wanted.

I used this tool and found that 1.4GB of my data was stored in two tables. A little more research showed we could change some application options and cut these tables in half. Not bad for a few hours work.

Update (11/26/2001): Brooks updated this script to add some additional reporting. He added a column to show the percentage of the space that an index is taking up and the percentage of the reserved space that is used. You can see his script in Script Library forum (here).

Discuss this article: 4 Comments so far. Print this Article.

If you like this article you can sign up for our weekly newsletter. There's an opt-out link at the bottom of each newsletter so it's easy to unsubscribe at any time.

Email Address:

Related Articles

Handling database file growth (18 December 2002)

Access MDB Files and SQL Server Device Files (16 August 2000)

Network Attached Storage: An Overview (11 July 2000)

SQL Server and Network Attached Storage (6 July 2000)

Other Recent Forum Posts

Replication fails after snapshot delivery (6 Replies)

SQL Database doesn’t work right why? (1 Reply)

Import multiple files to SQL table (0 Replies)

Sum function seems not to be working correctly (0 Replies)

document or pdf (1 Reply)

sql query need help (2 Replies)

SMS Text msg data Unreadable (1 Reply)

Merge replication Identity Issue (0 Replies)

Subscribe to SQLTeam.com

Weekly SQL Server newsletter with articles, forum posts, and blog posts via email. Subscribers receive our white paper with performance tips for developers.

SQLTeam.com Articles via RSS

SQLTeam.com Weblog via RSS

- Advertisement -