SqlServer queries all tables in a database and the total number of data and space occupied

  1. Query all data tables in a database
    SELECT name 数据表
    FROM sysobjects
    WHERE xtype='u'
    ORDER BY name

     

  2. Query all data tables and the total number of data in a database

    SELECT  a.name 数据表,
            b.rows 数据总条数
    FROM    sysobjects AS a
            INNER JOIN sysindexes AS b ON a.id = b.id
    WHERE   ( a.type = 'u' )
            AND ( b.indid IN ( 0, 1 ) )
    ORDER BY a.name,b.rows DESC;

     

  3. Query the space occupied by all data tables and the total number of data in a database

    SELECT  OBJECT_NAME(id) 数据表,
            RTRIM(8 * dpages) + 'KB' 占用空间大小,
            rows 数据总条数
    FROM    sysindexes
    WHERE   indid = 1
    ORDER BY rows DESC ,
            数据表 ,
            reserved DESC;

     

Guess you like

Origin blog.csdn.net/qubernet/article/details/107807491
Recommended