sql 2000中count(*),count(1),count(主键),count(非主键)等执行效率时间测试
2009年11月2日
没有评论
在一个133254条数据数据表中,分别通过执行以下语句采用方法一,结果大概如下
select count(*) from 表名 --133254条, 16ms
select count(1) from 表名--执行结果同count(*) 133254条, 16ms
select count(100) from 表名--执行结果同count(*) 133254条, 16ms
select count(ID) from 表名 --ID为主键,执行结果同count(*) 133254条, 16ms
select count(aa) from 表名--aa非主键字段1,数据有空值 129342条,46ms
select count(bb) from 表名--bb非主键字段2,数据有空值 132203条,46ms
通过以上测试后得出结论我们在用select count 查询返回的时候不要使用非主键,前面4条语句都可以