|sp_tableinfo - list tables and space usage|
About me and Nucleus
Articles, tips etc.
Courses and training
I frequently find myself writing some query to list all tables, including table size. This is a simple proc returning such information.
This script was written and tested on SQL Server 2008 R2. It should work on 2008 and 2005 as well.
See comment block in procedure source code for version history of the procedure.
The procedure returns a row for each table in current database (unless table spread over several filegroups, using several indexes or partitions; if so then several rows are returned). It returns schema name, table name, number of rows, size in both MB and pages and file group.
Name of table. Default is all tables in current database. Wildcards accepted (LIKE used in query).
The @sort parameter is used for sorting the result. The value is a single letter:
You find the code here.