EXEC sp_MSforeachtable @command1="select '?'", @command2="SELECT count(*) FROM ?"

解决方案 »

  1.   

    我是说能一次算出所有的表,
    因为我不知道会影响到那个表,如:
    表名     记录数
    table1   10000
    table2   100002
    .            .
    .            .
    .            .
      

  2.   

    declare @s varchar(8000)
    set @s=''
    select @s=@s+'select '''+name+''' as TableName, count(*) as Rows from '+name+' union ' from (select name from sysobjects where xtype='U')b group by name
    set @s=left(@s,len(@s)-6)
    exec (@s)--如果表太多会出问题
      

  3.   

    谢谢LouisXIV(夜游神)
    你的方法我测试了,但现在最头痛的是数据库中要近300多张表,我还是没办法解决啊,我知道这个办法很笨,各位高手能否指导一下:如何知道在操作某个表时会影响到其他的表
      

  4.   

    這樣好像可以吧
    declare @t_name varchar(50)
    select distinct [name] from sysobjects where  [id] in 
             (select [ID] from syscolumns where [name] in 
                 (select [name] from syscolumns where [ID] in
                   (select [ID] from sysobjects where xtype='U' and [name]=@t_name)))
      

  5.   

    select name,rowcnt from sysindexes where OBJECTPROPERTY(object_id(name), N'IsUserTable') = 1
      

  6.   

    chenshaizi(陈绍彬)的方法可以了,谢谢大家了,^_^