SQL to view the capacity size of a database table

Source: Internet
Author: User
Tags rtrim

1 --============== View the capacity size of a database table ========start================================?============2 Create Table#TableSpaceInfo--Create a result store table3 (4NameinfoNVarchar( -) , 5Rowsinfoint , 6ReservedNVarchar( -) , 7DatainfoNVarchar( -) , 8Index_sizeNVarchar( -) , 9UnusedNVarchar( -) Ten ) One  A  - Declare @TableName NVarchar(255)--Table name - Declare @CmdSql NVarchar( +) the  - DeclareInfo_cursorCursor  for - SelectO.name -  fromdbo.sysobjects o + Where ObjectProperty(O.id, N'istable')= 1  andO.name not  likeN'#%%' Order  byO.name -  + OpenInfo_cursor A  at Fetch Next  fromInfo_cursor -  into @TableName -  -  while @ @FETCH_STATUS = 0  - Begin -   If exists(Select *  fromDbo.sysobjectsWhereId=object_id(@tablename) and ObjectProperty(ID, N'isusertable')= 1)  in     Executesp_executesql N'Insert into #TableSpaceInfo Exec sp_spaceused @TBName'N'@TBName NVarchar (255)',@TBName = @TableName -  to   Fetch Next  fromInfo_cursor +    into @TableName  - End the  * CloseInfo_cursor $ deallocateInfo_cursorPanax Notoginseng GO -  the  + --Itlearner Note: Display database information Asp_spaceused@UpdateUsage = 'TRUE' the  + --Itlearner Note: Display table information - Select *  $  from#TableSpaceInfo $ Order  by cast( Left(LTrim(RTrim(Reserved)) ,Len(LTrim(RTrim(Reserved)))-2) as Int)Desc -  -  the Drop Table#TableSpaceInfo - --================ View the capacity size of a database table =====end========================?==========================

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.