sp_dba_table.sql | Database Journal

sp_dba_table.sql

Jan 8, 2007
1 minute read

>>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 intUser 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

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.