Solved

calculate schema size in sql server

Posted on 2008-10-30
7
1,868 Views
Last Modified: 2010-05-18
how to calculate the size of each schema in sql server 2005?
0
Comment
Question by:jung1975
[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
  • 2
7 Comments
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22845267
# of objects?  By type?  Size of Tables?  Size of indexes?

You have to provide more info.
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 22845323
schemas don't have a size..are you talking about the number of objects owned by a schema?
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 22845332
if so...


select * from sys.objects o
join sys.schemas s on o.schema_id = s.schema_id
where s.name = 'schemaname'
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:jung1975
ID: 22845542
I meant the size of tables own by a schema... can I get this number?
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 22849365
total rows of tables in the schema, or physical size?
0
 

Author Comment

by:jung1975
ID: 22849684
I 'd like to see both...
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 22849819
Here you go...this will give you a base resultset...you can query from this all you want:

      SELECT
            name = OBJECT_NAME (id),
            rows = convert (char(11), TheRowCount),
            reserved_KB = reservedpages * 8,
            data_KB = pages * 8,
            index_size_KB = CASE WHEN usedpages > pages THEN (usedpages - pages) ELSE 0 END * 8,
            unused_KB = CASE WHEN reservedpages > usedpages THEN (reservedpages - usedpages) ELSE 0 END * 8,
            schema_name = s.name
      FROM
      (
      SELECT id = object_id,
            reservedpages = SUM (reserved_page_count),
            usedpages = SUM (used_page_count),
            pages = SUM (
                  CASE
                        WHEN (index_id < 2) THEN (in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count)
                        ELSE lob_used_page_count + row_overflow_used_page_count
                  END
                  ),
            TheRowCount = SUM (
                  CASE
                        WHEN (index_id < 2) THEN row_count
                        ELSE 0
                  END
                  )
      FROM sys.dm_db_partition_stats p

      GROUP BY objecT_id
      ) a
      join sys.objects o On a.id = o.object_id
      join sys.schemas s On o.schema_id = s.schema_id
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with another query 10 39
SQL Session Remains Open After ReportViewerControl Form is Closed. 8 36
SQL Instance service gone? 5 39
Need SSIS project 2 30
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to take different types of Oracle backups using RMAN.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

726 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