Adenwei

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
---==============查看数据库表的容量大小========start================================?============
Create Table #TableSpaceInfo --创建结果存储表 
(
  NameInfo NVarchar(50) , 
  RowsInfo int , 
  Reserved NVarchar(20) , 
  DataInfo NVarchar(20) , 
  Index_Size NVarchar(20) , 
  Unused NVarchar(20) 
)


Declare @TableName NVarchar(255) --表名称
Declare @CmdSql NVarchar(1000)

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 NVarchar(255)', @TBName = @TableName

  Fetch Next From Info_Cursor 
  Into @TableName 
End

Close Info_Cursor 
Deallocate Info_cursor 
GO


--itlearner注:显示数据库信息 
sp_spaceused @UpdateUsage = 'TRUE'

--itlearner注:显示表信息 
Select * 
From #TableSpaceInfo 
Order By cast(left(lTrim(rTrim(Reserved)) , len(lTrim(rTrim(Reserved)))-2) As Int) Desc


Drop Table #TableSpaceInfo
---================查看数据库表的容量大小=====end========================?==========================

  

posted on 2016-10-10 12:27  Adenwei  阅读(162)  评论(0编辑  收藏  举报