/egilh

Learning by doing

I got the great query below from Michele today. It shows all the information you ever wanted to know about the tables in your SQL Server, in particular; the number of rows as well as the size of the data and index.

DECLARE @Tab sysname

 

DECLARE tables_Cursor CURSOR FOR

SELECT name

from sysobjects

WHERE xType='u'

 

OPEN tables_Cursor

 

      FETCH NEXT FROM tables_Cursor INTO @tab

 

WHILE @@FETCH_STATUS = 0

BEGIN

      select @tab
      -- Show space used by table

      exec ('sp_mstablespace ''' + @tab + '''')

      -- Show generic table info

      exec ('sp_help ''' + @tab + '''')

      FETCH NEXT FROM tables_Cursor INTO @tab

END

 

CLOSE tables_Cursor

DEALLOCATE tables_Cursor




Feel free to drop a few cents in the tip jar if this post saved you time and money

Post Comment
Title
 

Name
 

Url

Protected by Clearscreen.SharpHIPEnter the code you see:
Comment