與大家共享。
/********************************
功能:獲取表的空間分布情況  ycsoft 2005-07-13
**********************************/
if not exists (select * from dbo.sysobjects where id = object_id(n'[dbo].[tablespaceinfo]') and objectproperty(id, n'isusertable') = 1)
create table  tablespaceinfo                         --創建結果存儲表
              (nameinfo varchar(50) , 
               rowsinfo int , reserved varchar(20) , 
               datainfo varchar(20)  , 
               index_size varchar(20) , 
               unused varchar(20) )
delete from tablespaceinfo --清空數據表
declare @tablename varchar(255) --表名稱
declare @cmdsql varchar(500)
declare info_cursor cursor for 
select o.name  
from dbo.sysobjects o where objectproperty(o.id, n'istable') = 1 
     and o.name not like n'#%%'  order by o.name
open info_cursor
fetch next from info_cursor 
into @tablename 
while @@fetch_status = 0
begin
  if exists (select * from dbo.sysobjects where id = object_id(@tablename) and objectproperty(id, n'isusertable') = 1)
  execute sp_executesql 
         n'insert into tablespaceinfo  exec sp_spaceused @tbname',
          n'@tbname varchar(255)',
          @tbname = @tablename
  fetch next from info_cursor 
  into @tablename 
end
close info_cursor
deallocate info_cursor
go
--knowsky.com數據庫信息
sp_spaceused @updateusage = 'true'  
--表信息
select * 
from tablespaceinfo  
order by cast(left(ltrim(rtrim(reserved)) , len(ltrim(rtrim(reserved)))-2) as int) desc
備注:
| name | nvarchar(20) | 為其請求空間使用信息的表名。 | 
| rows | char(11) | 表中現有的行數。 | 
| reserved | varchar(18) | 表保留的空間總量。 | 
| data | varchar(18) | 表中的數據所使用的空間量。 | 
| index_size | varchar(18) | 表中的索引所使用的空間量。 | 
| unused | varchar(18) | 表中未用的空間量。 收集最實用的網頁特效代碼! 
 學習交流 
 
 熱門圖片 猜你喜歡的新聞 新聞熱點 2024-06-26 22:28:41 2024-06-26 22:26:16 2024-06-26 22:23:01 2024-06-25 19:29:23 2024-06-25 19:22:14 2024-06-25 19:19:15 疑難解答 |