Sunday, June 7, 2009

dev usage

IF OBJECT_ID('dbo.sp_dba_devusage') IS NOT NULL
BEGIN
    DROP PROCEDURE dbo.sp_dba_devusage
    IF OBJECT_ID('dbo.sp_dba_devusage') IS NOT NULL
        PRINT '<<<>>>'
    ELSE
        PRINT '<<<>>>'
END
go


create proc sp_dba_devusage
as
set nocount on

select distinct
     name = d.name,
     db_size = str(sum(u.size) / 512, 10, 1) + " MB",
     dbid = d.dbid,
     created = convert(char(14), d.crdate, 107)
     from master.dbo.sysdatabases d, master.dbo.sysusages u
     where d.dbid = u.dbid
     group by d.dbid, u.dbid
     order by d.dbid

declare @vsize int
select @vsize = low
from master.dbo.spt_values
where type="E"
  and number = 3

select device = substring(name,1,15),
       vdevno = convert(tinyint,substring(convert(binary(4),low),@vsize,1)),
       "default disk?" = "      " + substring("NY",(status & 1)+1,1),
       "total (MB)" = str(round((high-low)/512.,2),7,2),
       used = str(round(isnull(sum(size),0)/512.,2),7,2),
       free = str(round(abs((high-low-isnull(sum(size),0))/512.),2),7,2)
from master.dbo.sysusages u,
     master.dbo.sysdevices d
where vstart between low and high
  and cntrltype=0
group by all name
  having cntrltype=0
order by vdevno


go
EXEC sp_procxmode 'dbo.sp_dba_devusage','unchained'
go
IF OBJECT_ID('dbo.sp_dba_devusage') IS NOT NULL
    PRINT '<<<>>>'
ELSE
    PRINT '<<<>>>'
go
USE sybsystemprocs
go
GRANT EXECUTE ON dbo.sp_dba_devusage TO public
go

3 comments:

  1. Good one.very useful.

    Thx,
    SybaseTeam Member
    htpp://www.sybaseteam.com

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. thank you sorry I have kind of neglected this site just came back

    ReplyDelete