我想查出数据库A里面所有的表及表的数据条数?怎么用SQL语句写出?
谢谢!
-----------------------
      CSDN 论坛助手 
  http://china-csdn.cn

解决方案 »

  1.   

    create table AAA(id int identity(1,1),tablename varchar(50),[rowcount] int)delete from AAAexec sp_msforeachtable 'insert AAA(tablename, [rowcount]) select N''?'', count(*) from ?'select * from AAA
      

  2.   

    thanks-----------------------
          CSDN 论坛助手 
      http://china-csdn.cn
      

  3.   

    USE A
    EXEC sp_MSforeachtable @command1="print '?'",
             @command2="SELECT * FROM ?",
             @command3= "SELECT rows=count(*) FROM ? "
      

  4.   

    thanksbill024 (咖啡熊) 结早了点。不好意思
    -----------------------
          CSDN 论坛助手 
      http://china-csdn.cn
      

  5.   

    declare @sql varchar(2000)
    set @sql=''
    select @sql=@sql+'select '''+name+''',count(1) from '+name +' union all ' from sysobjects  d  where  d.xtype='U' 
    set @sql=left(@sql,len(@sql)-len('union all '))
    --print(@sql)
    exec(@sql)
    这样也可以~