TRY:count(主键)OR:count(索引列)

解决方案 »

  1.   

    sum(1)或:select a.name 表名,b.rows 记录数 from sysobjects a join sysindexes b on a.xtype='U' and a.status>0 and a.id=b.id and b.indid<2
      

  2.   

    那么大的数据量,没有必要作 count 啊,无论左右处理,count 的算法都是一样的。
      

  3.   

    真的要做统计吗???
    那就通过读系统表做吧主要是sysIndexes表里信息。
    相信你很快会解决
      

  4.   

    select count(1) from a1
      

  5.   

    try:
    select count(*) from tablename (index=clusteredindex,nolock)
      

  6.   

    以查询条件中的字段建立索引!或者 select top 1 * from table
    呵呵
      

  7.   

    用sum(1)快
    518195(数据)
    set noexec off set parseonly off SQL:StmtCompleted 0 0 0 0
    select IS_SRVROLEMEMBER ('sysadmin') SQL:StmtCompleted 0 0 0 0
    SET STATISTICS PROFILE ON     SQL:StmtCompleted 0 0 0 0
    select sum(1) from a   SQL:StmtCompleted 89 65 104 0
    select count(*) from a    SQL:StmtCompleted 32 180 104 0
    select count(cfh) from  a SQL:StmtCompleted 211 180 104 0
    SET STATISTICS PROFILE OFF   SQL:StmtCompleted 0 0 0 0
      

  8.   

    对大数据量的统计,应做定期的汇总处理。直接用count(*)不合理。当然,有条件的count(*)可以考虑,若对条件的字段加索引,速度还是可以接受的。另,做索引对count(*)没有什么的改进。
      

  9.   

    对,好象做索引对count(*)没有什么的改进
      

  10.   

    楼主为什么不用 sum(1) 呢?
      

  11.   

    如果不完全精确可以使用sp_spaceused 'Table'
      

  12.   

    select sum(1) from tablename
      

  13.   

    都是一样的, 50万+ 记录看:
    select count(*) from forumtopic
    select count(forumid) from forumtopic
    select count(topicid) from forumtopic
    select sum(1) from forumtopicIO:
    (1 row(s) affected)Table 'ForumTopic'. Scan count 1, logical reads 868, physical reads 0, read-ahead reads 0.(1 row(s) affected)Table 'ForumTopic'. Scan count 1, logical reads 868, physical reads 0, read-ahead reads 0.(1 row(s) affected)Table 'ForumTopic'. Scan count 1, logical reads 868, physical reads 0, read-ahead reads 0.(1 row(s) affected)Table 'ForumTopic'. Scan count 1, logical reads 868, physical reads 0, read-ahead reads 0.
      

  14.   

    to caiyunxia(monkey):你的那些信息哪里看到的?