SQL 快速获取行数量的方法

SQL 快速获取行数量的方法

方法1:

select count(*) from table1

缺点:随着数据量大,会越来越慢

方法2:

select count(id) from table1

只搜索其中一个字段,会快很多,或者这样写:

select count(1) from table1

方法3:

select rows from sysindexes where id = object_id('表名') and indid < 2
  • sysindexs 是对数据库里的数据表、索引的一个对应表.id 即定义的编号.(查找这个表的总行数.)
  • indid 指索引ID的类型: 0:堆   1:聚集索引   >1: 非聚集索引,  一般情况下表的indid是0

  

  

 

 

创建时间:2021.12.31  更新时间:

posted on 2021-12-31 09:18  滔Roy  阅读(2385)  评论(0编辑  收藏  举报

导航