SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Identify Large Tables

By Jesse McLain, 2008/03/13

Total article views: 754 | Views in the last 30 days: 33

The script can be run as-is, and will produce a report on the size of all user tables in the currently selected database. When I find that I need to trim the fat in a database, this report will quickly show where I can gain the most immediately. For example, a large table at the top of the results might have been created for a temporary purpose and can now be dropped, or perhaps is ripe for archiving older rows to a partition devoted to historical data.

The output consists of table name, number of rows, and its physical size, in kilobytes (including unused space), ordered by largest size to smallest.

I reluctantly used cursors for this, working with the assumption that the number of user tables in the database should be relatively small (numbering in the hundreds, or thousands at most), so that cursor performance would not be a problem. As a future improvement, I'd like to possibly convert this to set-based logic.

 

By Jesse McLain, 2008/03/13

Total article views: 754 | Views in the last 30 days: 33
Your response
 
 
Related tags

Maintenance    
T-SQL    
 
Related content

Collation Error 468

By Steve Jones | Category: T-SQL
| 2,468 reads

How to empty database

By Boka | Category: T-SQL
| 1,525 reads

Recompilation Feature

By Sur H | Category: T-SQL
(not yet rated) | 2,639 reads

Truncate Table

By | Category: T-SQL
(not yet rated) | 3,946 reads
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com