统计sql server 2012表的行数

--功能:统计sql server 2012表的行数
SELECT a.name,
       a.object_id,
       b.rows,
       b.index_id
FROM sys.tables AS a
    INNER JOIN sys.partitions AS b
        ON a.object_id = b.object_id
WHERE b.index_id IN ( 0, 1 );

sys.partitions系统视图:https://docs.microsoft.com/zh-cn/sql/relational-databases/system-catalog-views/sys-partitions-transact-sql?view=sql-server-2017

sys.tables系统视图:https://docs.microsoft.com/zh-cn/sql/relational-databases/system-catalog-views/sys-tables-transact-sql?view=sql-server-2017

--第二种方法

1 SELECT OBJECT_NAME(object_id) AS object_name,
2        rows
3 FROM sys.partitions
4 WHERE index_id IN ( 0, 1 )
5       AND object_id IN (
6                            SELECT object_id FROM sys.tables
7                        );

 

posted on 2019-07-04 15:55  hold_on_up  阅读(329)  评论(0编辑  收藏  举报