8

I am trying to get the table size for each table from a database using SQL Anywhere 11.

I just found out sp_spaceused has been deprecated

Any help with this would be greatly appreciated! :)

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
tray
  • 251
  • 1
  • 5
  • 14
  • Do you have a link confirming it's deprecation or is this speculation? – Dan P Apr 05 '12 at 20:28
  • found one. http://dcx.sybase.com/1001/en/dbwnen10/wn-newjasper-s-3751424.html – Dan P Apr 05 '12 at 20:30
  • Sorry I haven't found a work around. Gave you +1 on question because googling it for 15 - 20 mins can't find a thing on resolution. – Dan P Apr 05 '12 at 23:59

3 Answers3

6

Possibly the system view SYSTAB can be a good-enough alternative. It can give you the number of rows in the table, and it can give you how many pages the table uses. (In the sample below, I'm multiplying the number of pages by the DB's page size to get a total byte size.)

SELECT
    count,                      -- number of rows in the table
    (table_page_count * DB_PROPERTY('PageSize')) tablesize  
                                -- total size, in bytes
FROM SYSTAB
WHERE table_name = 'mytable';   -- or whatever limitations you want on 
                                -- the scope of the query

Hope this helps.

Dan K
  • 720
  • 10
  • 8
1

You can use this script at Sql Server to find the largest table in Database and row count

SELECT sc.name +'.'+ ta.name TableName
,SUM(pa.rows) RowCnt
FROM sys.tables ta
INNER JOIN sys.partitions pa
ON pa.OBJECT_ID = ta.OBJECT_ID
INNER JOIN sys.schemas sc
ON ta.schema_id = sc.schema_id
WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)
GROUP BY sc.name,ta.name
ORDER BY SUM(pa.rows) DESC  
0

To Add on to Dan K's answer.

SELECT
table_name,
count,                      
cast((table_page_count * DB_PROPERTY('PageSize')) as int) as Bytes,
cast(Bytes/1024 as varchar) + ' KB' as KB,
cast(Bytes/1024/1024 as varchar) + ' MB' as MB
FROM SYSTAB
WHERE creator = 1 
order by Bytes desc
Hainan Zhao
  • 1,962
  • 19
  • 19