EXEC sp_spaceused for all tables in my database

Posted on 2007-08-09
Last Modified: 2009-07-29
I can run EXEC sp_spaceused 'Tablename','TRUE' to get the size of my tables, is there any way I can run it for all so I can see which one takes the most space?
Question by:LegalZoomer
    LVL 75

    Assisted Solution

    by:Aneesh Retnakaran
    EXEC sp_MSForEachTable "EXEC sp_spaceused '?','TRUE' "

    Author Comment

    It works and then it fails:

    The query has exceeded the maximum number of result sets that can be displayed in the results grid. Only the first 100 result sets are displayed in the grid.
    LVL 9

    Accepted Solution

    Try this:

    create table #TableStatistics (tablename varchar(128), rowcnt int, reserved varchar(10), data varchar(10), index_size varchar(10), unused varchar(10))
    exec sp_MSforeachtable
       'insert into #TableStatistics EXEC sp_spaceused ''?'' '
    select * from #TableStatistics
        order by rowcnt desc
    drop table #TableStatistics
    LVL 9

    Expert Comment

    I was in the middle of testing this but then I saw that aneeshattingal beat me to it. Basicaly you insert it to a temp table which wont have the limit of 100.
    LVL 68

    Expert Comment

    Or set QA output to text instead of grid; I don't think text output has that limit either.

    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

    Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

    755 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

    16 Experts available now in Live!

    Get 1:1 Help Now