SQL 查看數據庫表的容量大小


 1 --==============查看數據庫表的容量大小========start================================?============
 2 Create Table #TableSpaceInfo --創建結果存儲表 
 3 (
 4   NameInfo NVarchar(50) , 
 5   RowsInfo int , 
 6   Reserved NVarchar(20) , 
 7   DataInfo NVarchar(20) , 
 8   Index_Size NVarchar(20) , 
 9   Unused NVarchar(20) 
10 )
11 
12 
13 Declare @TableName NVarchar(255) --表名稱
14 Declare @CmdSql NVarchar(1000)
15 
16 Declare Info_Cursor Cursor For
17 Select o.Name 
18 From dbo.sysobjects o 
19 Where objectProperty(o.ID, N'IsTable') = 1 and o.Name not like N'#%%' Order By o.Name
20 
21 Open Info_Cursor
22 
23 Fetch Next From Info_Cursor 
24 Into @TableName
25 
26 While @@FETCH_STATUS = 0 
27 Begin
28   If exists (Select * From dbo.sysobjects Where ID=object_ID(@tablename) and objectProperty(ID, N'IsUserTable') = 1) 
29     Execute sp_executesql N'Insert Into #TableSpaceInfo Exec sp_Spaceused @TBName', N'@TBName NVarchar(255)', @TBName = @TableName
30 
31   Fetch Next From Info_Cursor 
32   Into @TableName 
33 End
34 
35 Close Info_Cursor 
36 Deallocate Info_cursor 
37 GO
38 
39 
40 --itlearner注:顯示數據庫信息 
41 sp_spaceused @UpdateUsage = 'TRUE'
42 
43 --itlearner注:顯示表信息 
44 Select * 
45 From #TableSpaceInfo 
46 Order By cast(left(lTrim(rTrim(Reserved)) , len(lTrim(rTrim(Reserved)))-2) As Int) Desc
47 
48 
49 Drop Table #TableSpaceInfo
50 --================查看數據庫表的容量大小=====end========================?==========================

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM