<pre>
create sp_space as 

-- Posted to c.d.s. by Ty Moser <tmoser@iquest.net> 8/11/97
-- This section prints out all usage on each device by database

select  "Device Name"   = convert(char(15), dev.name)
   ,"Avail (MB)"   = (((high - low) + 1) / 512)
   ,"Used (MB)"    = sum(isnull(size, 0)) / 512
   ,"# Fragments"  = count(vstart)
   ,"Database"     = isnull(convert(char(15), db_name(usage.dbid)),
                     "** Not Used **")

from master..sysusages usage, master..sysdevices dev
where low/16777216 *= vstart/16777216
  and dev.status <> 16
group by dev.name
        ,((high - low) + 1) / 512
        ,usage.dbid
order by dev.name, db_name(usage.dbid)        

go
