8

我正在尝试使用 SQL Anywhere 11 从数据库中获取每个表的表大小。

我刚刚发现sp_spaceused已被弃用

对此的任何帮助将不胜感激!:)

4

3 回答 3

6

系统视图 SYSTAB 可能是一个足够好的替代方案。它可以为您提供表格中的行数,并且可以为您提供表格使用的页数。(在下面的示例中,我将页数乘以数据库的页大小以获得总字节大小。)

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

希望这可以帮助。

于 2012-10-16T00:14:39.343 回答
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  
于 2012-11-27T21:41:15.363 回答
0

添加到 Dan K 的答案。

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
于 2021-01-18T03:00:52.383 回答