Solved

calculate schema size in sql server

Posted on 2008-10-30
7
1,910 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to take different types of Oracle backups using RMAN.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

734 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