• Jeff Moden (1/22/2016)


    river1 (1/20/2016)


    Hi,

    I have a list of tables (several tables) and I would like to know their size.

    Is there a way to know that using t-sql?

    It will be easyer then having to select each one from the diagram or having to look at the reports, one by one...

    Thank you

    WHICH size? Reserved? Used? Data Size? Index Size? Unused?

    Don't answer that. It's a rhetorical question.

    Rather than messing around with sp_space used or some unsupported stored procedure that runs a cursor in the background, open the code for sp_SpaceUsed and see how they did it. Then, convert it to a set based wonder of your own making to work against one or all of the tables in the current database.

    I'd post my own creation in this area but then the only thing you'd learn is how to use my stuff. If you take the time to look at the code of sp_SpaceUsed, you're going to learn and remember stuff that will help you throughout your career.

    Hmmm. I wrote a procedure to get the space for all the tables in a database, but it's a wrapper to sp_spaceused to build each row. Now you've got me thinking I really need to dig into sp_spaceused itself.

    Thanks a lot, Jeff. Now I have something else to do. 😛 That's okay though, I know I'll have fun with it.