sql2005中,如何计算一个库里各个表的记录总数,全用T-SQL语言来实现谢谢

解决方案 »

  1.   

    --这样?
    select count(name) from syscolumns where id=object_id('TableName')
      

  2.   

    EXEC sp_MSforeachtable ' select ''表名:?;记录数:'' +ltrim(count(*)) from ?' 
      

  3.   

    --SQL 2000是这样的,2005中把系统表换一下就可以。
    select b.name,a.rowcnt from sysindexes a,sysobjects b 
    where a.id=b.id and a.indid<2 and b.xtype='u' --and rowcnt>100000
      

  4.   

    select rows from sysindexes where id in (select id from sysobjects where xtype = 'u') 
    and indid in (0,1) 
      

  5.   

    SELECT o.name AS "Table Name", i.rowcnt AS "Row Count"
    FROM sysobjects o, sysindexes i
    WHERE i.id = o.id
    AND i.indid IN(0,1)
    AND o.xtype = 'u' --只统计用户表
    AND o.name <> 'sysdiagrams'
    ORDER BY i.rowcnt DESC --按行排降序COMPUTE SUM(i.rowcnt), count(o.name); --汇总行数,表数
    GO
      

  6.   


    declare @TableRow table
    (tableName sysname,
    RowCnt int)insert into @TableRow exec sp_msforeachTable 'select ''?'', count(*) ''?_RowCnt'' from ?'
    select * from @TableRow
    order by RowCnt desc