select count(*) 与select count(1) 区别

bigo808 2007-03-05 01:56:52
select count(*) from table
与select count(1) from table
的对象和速度区别?
...全文
4077 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yueliangchuaner 2011-07-29
  • 打赏
  • 举报
回复
据oracle官方资料透露,count(*) 比count(1)快
[Quote=引用 3 楼 loveqong 的回复:]
select count(*) from table 返回table表里面的记录总数
select count(1) from table 返回首行首列.
[/Quote]
westqueen 2008-11-15
  • 打赏
  • 举报
回复
count(1)不见得总是比count(*)执行速度快啊,,,
flyrain521 2008-10-13
  • 打赏
  • 举报
回复
第一句是对的.第二句就错了.count(1)并不是针对第一列,你可以试试count('A')
同样是可以得到整个表的记录数的.这里只是用一个实际值罢了.当然也可以是一个字符串.count('Aasd')都是可以的.
这种采用实际值的例子比用*都要快.因为它执行的时候不是扫描整个表
guoxing426 2007-07-28
  • 打赏
  • 举报
回复
当然是 select count(*) 比select count(1)要慢了
select count(*)是统计表中所有记录个数
而select count(1)是返回首行
loveqong 2007-06-27
  • 打赏
  • 举报
回复
select count(*) from table 返回table表里面的记录总数
select count(1) from table 返回首行首列.
greatlsd 2007-06-16
  • 打赏
  • 举报
回复
同问
hui_hui_2007 2007-03-05
  • 打赏
  • 举报
回复
应该没有区别的.

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧