dcsimg

sp_dba_table.sql

January 8, 2007



>>Script Language and Platform: Sybase Transact SQL
This stored procedure displays user of system table list ordered by size (Ko).

Author: jflebon


use sybsystemprocs
go

if exists (select name from sybsystemprocs..sysobjects 
  where name="sp_dba_table" and type="P")
   begin
        drop procedure sp_dba_table
   end
go

create procedure sp_dba_table @tabletype char(1) = NULL
as
/*

 *@(#) Author   : JF LEBON
 *@(#) Version  : 1.0
 *@(#) Date     : 28/03/2004
 *@(#) Syntax   : exec sp_dba_table <table type> 'S' system tables 'U' user table
 *@(#) Comments :
 *@(#) Changes  :

 */

set nocount on

-- Nobody but SA !
if suser_id() !=1
   begin
        print "WARNING: You have to be SA to execute this procedure."
	return (1)
   end

-- Never use it inside a transaction !
if @@trancount > 0
   begin
   	print "WARNING: You can NOT use this procedure inside a transaction."
	return (1)
   end

-- Few variables...
declare @page_size int

-- User tables or System tables, if none default is 'S' system tables...
if @tabletype is not null
   begin
        select @tabletype = upper(@tabletype)
        if @tabletype not in ('U','S') begin goto USAGE end
   end
else
    begin
         select @tabletype = 'S'
    end

-- What is the dataserver's page size ?
select @page_size = low/1024 from master.dbo.spt_values where type = 'E' and number = 1

-- Enjoy your flight !
select name = o.name,
       row_total = convert(real,sum(rowcnt(i.doampg))),
       data_size = convert(real,sum(convert(numeric(32, 9),data_pgs(i.id, i.doampg)) * @page_size)),
       index_size = convert(real,sum(convert(numeric(32, 9),data_pgs(i.id, i.ioampg)) * @page_size)),
       reserved = convert(real,sum(convert(numeric(32, 9),(reserved_pgs(i.id, i.doampg) + reserved_pgs(i.id, i.ioampg))) * @page_size)),
       unused = convert(real,sum(convert(numeric(32, 9),((reserved_pgs(i.id, i.doampg) + reserved_pgs(i.id, i.ioampg))
	        - (data_pgs(i.id, i.doampg) + data_pgs(i.id, i.ioampg)))) * @page_size))
from master.dbo.spt_values d, sysobjects o, sysindexes i
     where o.type in (@tabletype) and o.id = i.id and d.number = 1 and d.type = "E"
     group by o.id order by data_size desc

return (0)

USAGE:
print "USAGE: exec sp_dba_table ['table type']"
print "Exemple: exec sp_dba_table 'U'"
print "         exec sp_dba_table 'S'"
go


Disclaimer: We hope that the information on these script pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness, or fitness for a particular purpose... Disclaimer Continued


Back to Database Journal Home








The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers