码迷,mamicode.com
首页 > 数据库 > 详细

查看MSSQLServer2008数据库表占存储空间的sql

时间:2016-10-10 14:18:41      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

---==============查看数据库表的容量大小========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========================?==========================

  

查看MSSQLServer2008数据库表占存储空间的sql

标签:

原文地址:http://www.cnblogs.com/adenwei/p/5945314.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!