SQL Server查询表行数

    技术2024-11-24  19

    方式一:(表大时较慢)

    select count(*) as rows from table_name

    方式二:(数据库里本身存的信息,速度较快)

    SELECT a.name, b.rows,b.indid FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.id WHERE b.indid in (0,1) and a.name = 'table_name' ORDER BY a.name,b.rows DESC

    如查询表DM_FACT_SALES的数据行数

    SELECT a.name, b.rows,b.indid FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.id WHERE b.indid in (0,1) and a.name = 'DM_FACT_SALES' ORDER BY a.name,b.rows DESC
    Processed: 0.053, SQL: 9