use
information_schema
select
table_name,table_rows
from
tables
where
TABLE_SCHEMA
=
'数据库名'
order
by
table_rows
desc
两种计算方法,第一种最为容易想到:
sql="select
*
from........."
set
rs=...
sum=0
do
until
rs.eof
sum=sum+rs("price")
rs.movenext
loop
set
rs=nothing
sum
就是所要的值。
第二种方法:
sql="select
sum(price)
from.........",是最好的,效率最高的。
select d.name as 表名,COUNT (*)as 记录 from syscolumns a inner join sysobjects d on a.id = d.id and d.xtype = 'U'group by d.name
这是sqlserver 实现的,不知道符不符合。不过刚刚验证了一下,不是很对,估计是主键的原因,修改好了再看看
以上语句只能测试出部分,这个存储过程可以实现全部,sqlserver直接执行即可:
create table #temp(Recordcount int ,tableName varchar(30))
declare @tablename varchar(30)
declare @sql varchar(100)
declare @str varchar(30)
declare tablecursor cursor for
select name from sysobjects where xtype='u'
open tablecursor
fetch next from tablecursor into @tablename
while @@fetch_status=0
begin
set @str=@tablename
set @sql='insert into #temp(recordcount,tablename) select count(*),'+''''+@tablename+''''+' from '+@tablename
exec(@sql)
fetch next from tablecursor into @tablename
end
close tablecursor
deallocate tablecursor
select * from #temp drop table #temp
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)