zoukankan      html  css  js  c++  java
  • 统计数据库表信息的脚本

    --Get Table usage space

    if object_id(N'tempdb..[#TableSizes]') is not null

      drop table #TableSizes ;

    /*—————————————————————————-*/

    /* Create the temp table                                                     */

    /*—————————————————————————-*/

    create table #TableSizes

      (

        [Table Name] nvarchar(128)   /* Name of the table */

      , [Number of Rows] char(11)    /* Number of rows existing in the table. */

      , [Reserved Space] varchar(18) /* Reserved space for table. */

      , [Data Space] varchar(18)    /* Amount of space used by data in table. */

      , [Index Size] varchar(18)    /* Amount of space used by indexes in table. */

      , [Unused Space] varchar(18)   /* Amount of space reserved but not used. */

      ) ;

    /*—————————————————————————-*/

    /* Load the temp table                                                        */

    /*—————————————————————————-*/

    declare @schemaname varchar(256) ;

    -- Make sure to set next line to the Schema name you want!

    set @schemaname = 'dbo' ;

    -- Create a cursor to cycle through the names of each table in the schema

    declare curSchemaTable cursor

      for select sys.schemas.name + '.' + sys.objects.name

          from    sys.objects

                , sys.schemas

          where   object_id > 100

                  and sys.schemas.name = @schemaname

                  /* For a specific table uncomment next line and supply name */

                --and sys.objects.name = ’specific-table-name-here’   

                  and type_desc = 'USER_TABLE'

                  and sys.objects.schema_id = sys.schemas.schema_id ;

    open curSchemaTable ;

    declare @name varchar(256) ;  /* This holds the name of the current table*/

    -- Now loop thru the cursor, calling the sp_spaceused for each table

    fetch curSchemaTable into @name ;

    while ( @@FETCH_STATUS = 0 )

      begin    

        insert into #TableSizes

                exec sp_spaceused @objname = @name ;       

        fetch curSchemaTable into @name ;   

      end

    -- Important to both close and deallocate!

    close curSchemaTable ;     

    deallocate curSchemaTable ;

    /*—————————————————————————-*/

    /* Feed the results back                                                     */

    /*—————————————————————————-*/

    select [Table Name] AS TableName

        , [Number of Rows] AS NoOfRows

        , REPLACE([Reserved Space],'KB','') AS [ReservedSpace]

        , REPLACE([Data Space],'KB','') AS [DataSpace]

        , REPLACE([Index Size],'KB','') AS [IndexSize]

        , REPLACE([Unused Space],'KB','') AS [UnusedSpace]


    from    [#TableSizes]

    order by CAST ([Number of Rows] AS INT) DESC

    --order by [Table Name] ;

    /*—————————————————————————-*/

    /* Remove the temp table                                                     */

    /*—————————————————————————-*/

    drop table #TableSizes ;

  • 相关阅读:
    一种无法被Dump的jar包加密保护解决方案
    基于设备指纹零感验证系统
    IOS防作弊产品技术原理分析
    某移动端防作弊产品技术原理浅析与个人方案构想
    web安全防御之RASP技术
    Linux漏洞分析入门笔记-Off-By-One(栈)
    smb中继学习
    Dedecms sp2 5.7 后台getshell审计
    phpmyadmin后台代码执行分析复现
    静态恶意代码逃逸-学习一
  • 原文地址:https://www.cnblogs.com/micolour/p/1774389.html
Copyright © 2011-2022 走看看