sqlserver查询数据的所有表名和行数及空间占用量
Posted 前端
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlserver查询数据的所有表名和行数及空间占用量相关的知识,希望对你有一定的参考价值。
//查询所有表名 select name from sysobjects where xtype=‘u‘
SELECT name, object_id, principal_id, schema_id, parent_object_id, type, type_desc, create_date, modify_date, is_ms_shipped, is_published,
is_schema_published, lob_data_space_id, filestream_data_space_id, max_column_id_used, lock_on_bulk_load, uses_ansi_nulls, is_replicated,
has_replication_filter, is_merge_published, is_sync_tran_subscribed, has_unchecked_assembly_data, text_in_row_limit,
large_value_types_out_of_row
FROM sys.tables
//查询数据库中所有的表名及行数
SELECT a.name, b.rows
FROM sys.sysobjects AS a INNER JOIN
sys.sysindexes AS b ON a.id = b.id
WHERE (b.indid IN (0, 1)) AND (a.type = ‘u‘)
ORDER BY a.name, b.rows DESC
//查询所有的标明及空间占用量\行数
SELECT OBJECT_NAME(id) AS tablename, 8 * reserved / 1024 AS reserved, RTRIM(8 * dpages) + ‘kb‘ AS used, 8 * (reserved - dpages) / 1024 AS unused,
8 * dpages / 1024 - rows / 1024 * minlen / 1024 AS free
FROM sys.sysindexes
WHERE (indid = 1)
ORDER BY tablename, reserved DESC
以上是关于sqlserver查询数据的所有表名和行数及空间占用量的主要内容,如果未能解决你的问题,请参考以下文章