Top 5 tables by size

  • Hi all,

       Here is my query that how to get the top 5 tables by size for a particular database?

    Would any one provide a dynamic query for that?

    Any suggestions would be helpful to me..

    Thanks,

    Bagath.

  • Try this:

    Script to analyze table space usage

    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61762

     

     

     

  • Thanks You very much ...:-)

     

    Cheers,

    Bagath

  • Hey Micheal!  Welcome aboard!  Have seen lot's of your posts on the "other" forum... glad to see another intelligent person come on (well, except for the cursor )

     

    By the way... if you write a long post, be sure to do a "copy" before you try to submit your post... dunno what it is but after a time, this forum post engine seems to "lose it's mind" and all will be lost when you finally go to post.  Always do a "copy" of the text in your post before you submit it.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • try this

    SELECT TOP 5 OBJECT_NAME(id),ROWS FROM sysindexes ORDER BY [ROWS] desc

  • Well, somtimes you just need a cursor.

    There are no dumb tools, just dumb workmen. 

     

     

  • Hey,

    Thanks allot for your great responce and suggestions.Will try to continue like that only.

    Once again thanks to all of you.

    Cheers,

     

  • Actually, if you have more than one index on a large table, you'll get back duplicate results.

    eg: The results from one of our databases

    name rows

    ---- ----

    fr_extract 5668928

    fr_extract 5668928

    fr_extract 5668928

    fr_extract 5668928

    invoiceqty04 4330914

    Try this instead; pick up the maximum rows indexed for each table, and then pick up the top 5 tables:

    select top 5 [name], [rows]

    from (

    SELECT OBJECT_NAME(id) [name], max(rows) [rows]

    FROM [sysindexes]

    group by OBJECT_NAME(id)

    ) inner_query

    order by rows desc

  • If you want to have the top 5 biggest table (by szize and not by the number of rows) then you can use this one:

    select  top 5

     O.name,

     Pages = reserved,

     KB_used = reserved * 8

    from sysindexes I join sysobjects O on O.id = I.id

    where indid < 2

    order

    by reserved desc

    But don't forget: this is not 100% up to date! To have a more relevant information you should run dbcc updateusage before



    Bye
    Gabor

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply