Solved

calculate schema size in sql server

Posted on 2008-10-30
7
1,788 Views
Last Modified: 2010-05-18
how to calculate the size of each schema in sql server 2005?
0
Comment
Question by:jung1975
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now