• 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========================?==========================
  • 相关阅读:
    关于Winsock编程中IO重叠的概念
    comparator接口与Comparable接口的区别
    String、StringBuffer与StringBuilder之间区别
    Oracle 中 call 和 exec的区别
    谈谈对Spring IOC的理解(转)
    常见的几种RuntimeException
    long(Long)与int(Integer)之间的转换
    ValueStack值栈和ActionContext
    Struts2执行过程解析
    Struts2的经典入门
  • 原文地址:https://www.cnblogs.com/chengulv/p/3738076.html
Copyright © 2020-2023  润新知