比如说我有个数据库名为haha
其中有表a,b,c,d,e,f,g,h
如何查询指定表占用空间大小
比如说表a 
用语句实现
谢谢

解决方案 »

  1.   

    declare @i int--統計表的數目
    declare @aa varchar
    set@i=1
    while @aa<>''
    set@aa=substring(abcdefg,@i)--把表名放在一起
    sp_spaceused '@aa'
    set@i=@i+1
    loop
      

  2.   

    修正
    declare @i int--統計表的數目
    declare @aa varchar(20)
    --set @i=1
    while @aa<>''
    SET @aa=(substring('ABCDEFG',@i,1))--把表名放在一起
    EXEC sp_spaceused @aa
    set @i=@i+1
      

  3.   

    use hahadeclare @tbname varchar(1000)
    declare cu cursor for
    select   name   from   sysobjects   where   xtype   ='U'
    open cu
    fetch cu into @tbname
    while(@@fetch_status=0)
    begin
    EXEC sp_spaceused @tbname
    fetch cu into @tbname
    end
      

  4.   

    忘了释放游标了
    declare @tbname varchar(1000)
    declare cu cursor for
    select   name   from   sysobjects   where   xtype   ='U'
    open cu
    fetch cu into @tbname
    while(@@fetch_status=0)
    begin
    EXEC sp_spaceused @tbname
    fetch cu into @tbname
    end
    close cu
    deallocate cu
      

  5.   

    exec sp_MSforeachtable 'exec sp_spaceused ''?'''