请问如何优化select count(*) from tb1的索引 select count(id) from tb1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select count(*) from tb1=====>select count(1) from tb1 用了select count(id) from tb1或select count(1) from tb1都不会改成聚集索引进行优化,仍然用普通索引 select count(1) from tb1 select count(1) from tb1正解 select count(*) from tb1 where id>0 select count(id) from tb1 select count(1) from tb1 http://www.blog.com.cn/user25/lijunyi/archives/2005/213533.shtml select count(1) from tb1,select count(id) from tb1,select count(*) from tb1的执行效率是一样的。 如果你的count(1) 使用了聚集索引,反而是最慢的。你需要选择全部数据,此时必须遍历,如果遍历聚集索引,实际上是对实际的数据页进行扫描。这反而是最差的。你可以建一个聚集索引,那一个非聚集索引,比较一下会使用什么索引?-------------------http://chinadba.cn最具实战经验的数据库优化,管理,设计,培训网目前更新了二篇文档 在sql里面想取得用时间列排序最新的。。头三列。sql命令怎么写 SQL 的修改。。。。。。。。 C/S程序,有独立数据库服务器,如何做到:不让我SQL Server中的任何代码被人随便看,同时只让用户动他该动的数据 求一个难度的sql语句。。。 内网远程访问外网的sql2000数据库 多表查询的问题,请各位帮帮我。 如何将combobox绑顶到数组? 菜鸟问题 关于@@ROWCOUNT的问题。。。 sql2008 创建视图合并表的问题,求助 关于存储过程的sql语句,请指教 用变量代替"C:\yd.xls"文件路径,100分相送!
正解
from tb1
的执行效率是一样的。
-------------------
http://chinadba.cn
最具实战经验的数据库优化,管理,设计,培训网
目前更新了二篇文档