给大家Share 一个获取数据库内表大小的存储过程,希望大家有用到,注意一下username改成应用的用户名。
create procedure sp_gettablesize
as
begin
    declare @tablename char(100)
    declare tabname_cur cursor for select Table_owner+'.'+table_name from sp_iqtable() where table_type='BASE' and server_type='IQ' and Table_owner='username'
    create table #tablesize_temp(
      tablename char(100) null,
      kbytes integer
    )
    open tabname_cur
    fetch tabname_cur into @tablename
    while(@@sqlstatus = 0)
    begin
        fetch tabname_cur into @tablename
        insert into #tablesize_temp select tablename,convert(integer,kbytes) as kbytes from sp_iqtablesize(@tablename)
    end
    close tabname_cur
    deallocate cursor tabname_cur
    select top 100 tablename,kbytes from #tablesize_temp order by kbytes desc
end


09-21 22:57