Solved

calculate schema size in sql server

Posted on 2008-10-30
7
1,768 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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.
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to recover a database from a user managed backup

760 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

19 Experts available now in Live!

Get 1:1 Help Now