Friday, December 23, 2011

Top 10 large tables in database

Top 10 largest tables in a database by rowcount:
select

top 10

    name,

    row_count(db_id(), id)

from

    sysobjects

order by

    row_count(db_id(),id) desc

Top 10 largest tables in a database by allocated space:

select

top 10

    name,

    reserved_pages(db_id(),id)

/(1024.0 / (@@maxpagesize/1024.0) ) as "Allocated MB"

from

    sysobjects

order by

    reserved_pages(db_id(),id) desc

go

Top 10 largest tables in a database by used allocated space:

select

top 10

    name,

    used_pages(db_id(),id)

/(1024.0 / (@@maxpagesize/1024.0) ) as "Used MB"

from

    sysobjects

order by

    used_pages(db_id(),id)(db_id(),id) desc

go 
**These are not my own queries..Credit goes to Bret Halford on sybase forums.
Top 10 largest tables in a database by rowcount:
select

top 10

    name,

    row_count(db_id(), id)

from

    sysobjects

order by

    row_count(db_id(),id) desc

Top 10 largest tables in a database by allocated space:

select

top 10

    name,

    reserved_pages(db_id(),id)

/(1024.0 / (@@maxpagesize/1024.0) ) as "Allocated MB"

from

    sysobjects

order by

    reserved_pages(db_id(),id) desc

go

Top 10 largest tables in a database by used allocated space:

select

top 10

    name,

    used_pages(db_id(),id)

/(1024.0 / (@@maxpagesize/1024.0) ) as "Used MB"

from

    sysobjects

order by

    used_pages(db_id(),id)(db_id(),id) desc

go 
**These are not my own queries..Credit goes to Bret Halford on sybase forums.

2 comments:

romain said... June 8, 2015 at 7:13 PM

Hi ! Many thanks !

There's an error on the last part ( Top 10 largest tables in a database by used allocated space: ):

used_pages(db_id(),id)(db_id(),id) desc

must be

used_pages(db_id(),id) desc

Anonymous said... August 29, 2023 at 6:24 PM

He has copied it twice in the order by clause. remove one of them and it will work.

Post a Comment