Solved

SQL 2005 Table Size

Posted on 2011-02-12
4
272 Views
Last Modified: 2012-05-11
Hi,

  I need a query to collect the top 20 tables size for mty SQL 2005 database.

Thanks
0
Comment
Question by:ITMaster1979
4 Comments
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 83 total points
ID: 34881508
0
 
LVL 15

Assisted Solution

by:Aaron Shilo
Aaron Shilo earned 83 total points
ID: 34881629
hi
this should help you.

EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'"

--

CREATE PROCEDURE #TableSpaceUsed
AS

-- Create the temporary table...
CREATE TABLE #tblResults
(
   [name]   nvarchar(255),
   [rows]   int,
   [reserved]   varchar(255),
   [reserved_int]   int default(0),
   [data]   varchar(255),
   [data_int]   int default(0),
   [index_size]   varchar(255),
   [index_size_int]   int default(0),
   [unused]   varchar(255),
   [unused_int]   int default(0)
)


-- Populate the temp table...
EXEC sp_MSforeachtable @command1=
         "INSERT INTO #tblResults
           ([name],[rows],[reserved],[data],[index_size],[unused])
          EXEC sp_spaceused '?'"
   
-- Strip out the " KB" portion from the fields
UPDATE #tblResults SET
   [reserved_int] = CAST(SUBSTRING([reserved], 1,
                             CHARINDEX(' ', [reserved])) AS int),
   [data_int] = CAST(SUBSTRING([data], 1,
                             CHARINDEX(' ', [data])) AS int),
   [index_size_int] = CAST(SUBSTRING([index_size], 1,
                             CHARINDEX(' ', [index_size])) AS int),
   [unused_int] = CAST(SUBSTRING([unused], 1,
                             CHARINDEX(' ', [unused])) AS int)
   
-- Return the results...
SELECT * FROM #tblResults order by reserved_int desc


-- drop procedure TableSpaceUsed
-- exec TableSpaceUsed
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 84 total points
ID: 34883692
Why re-invent the wheel: There is a standard report in SSMS that already gives you that information:
1. Object Explorer.
2. Right-click the database.
3. Reports
4. Standard Reports
5. Disk Usage by Top Tables.
0
 
LVL 1

Author Closing Comment

by:ITMaster1979
ID: 35020282
good solution
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question