如何统计库中所有表的行数?!
网上海搜了一通才发现原来有个系统存储过程可以调用:sp_msforeachtable
具体使用方法如下:
//创建临时表
create table ##RowCount(
tableName varchar(500),
dataCount int
)
//执行存储过程
exec sp_msforeachtable 'insert into ##RowCount (tableName,dataCount) select ''?'' tableName, count(*) dataCount from ?'
//查询结果
select * from ##RowCount
or
select * from ##RowCount where tablename like '%SRC%'
也可以直接执行存储过程:
exec sp_msforeachtable 'select ''?'',count(*) from ?'