Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL 2005 Table Size

Posted on 2011-02-12
4
Medium Priority
?
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 75

Assisted Solution

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

Assisted Solution

by:Aaron Shilo
Aaron Shilo earned 249 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 252 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

704 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