Table and Index sizes

  • Hi everyone,

    How can I check the size of each table and index in my database? Thanks in advance for your help.

  • Try: sp_spaceused Table_name

  •  sp_msforeachtable 'sp_spaceused ''?''' 
  • Thanks guys, I liked both answers, but the sp_msforeachtable can be very handy.

    One more question:

    How can I check the full text of the sql statement that is being run. In other words, I have a SPID and I want to see the full sql for that SPID. How can I see that? Thanks again.

  • DBCC INPUTBUFFER() will give you the last statement executed.

    or use Profiler to capture statements as they happen.

    K. Brian Kelley

    bkelley@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/bkelley/

    K. Brian Kelley
    @kbriankelley

  • OK, here is why I need to get the full text for each SPID.

    I wrote stored procedure that will give me the amount of CPU and I/O used over a period of time. So, basically, if a process is using a lot of CPU and/or I/O, I can see it. For this reason, I like to also add to my stored procedure a column that has the FULL sql statement that is being run for each SPID. EM only shows you part of the sql statement, which is not good for performance tuning of sql statements.

    So, I need to the full sql statement because:

    1. It is more convenient to have everything in my procedure instead of taking the SPID from my procedure and checking the sql statement in EM.

    2. EM only gives me partial sql statements, which does not allow me to do sql performance tuning.

    Any ideas where the sql statements are stored? Thanks again guys.

  • Profiler will capture all this information. Save the information to a trace file. Then, in order to analyze it, open up your trace file and save it to a trace table.

    K. Brian Kelley

    bkelley@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/bkelley/

    K. Brian Kelley
    @kbriankelley

  • Profiler would be a better solution for tracking usage over some time period.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

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

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