这是我以前写的一段简化的等同sp_spaceused的语句(sybase)
希望你可以使用
declare @slog_res_pgs numeric(20, 9), /* number of reserved pgs. in syslogs */
@slog_dpgs numeric(20, 9) , /* number of data pages in syslogs */
@unreserved numeric(11, 0)
declare @doampg int
select @doampg = doampg from sysindexes where id = 8
select @slog_res_pgs = convert(numeric(20, 9), reserved_pgs(8, @doampg)),
@slog_dpgs = convert(numeric(20, 9), data_pgs(8, @doampg))
select distinct
s.name,
s.id,
res_pgs = 0,
low = d.low,
dpgs = convert(numeric(20, 9), s.doampg),
ipgs = convert(numeric(20, 9), s.ioampg),
unused = convert(numeric(20, 9), 0)
into #pgcounts
from sysindexes s, master.dbo.spt_values d
where s.id != 8
and d.number = 1
and d.type = "E"
having d.number = 1
and d.type = "E"
update #pgcounts set
res_pgs = reserved_pgs(id, dpgs) + reserved_pgs(id, ipgs),
dpgs = convert(numeric(20, 9), data_pgs(id, dpgs)),
ipgs = convert(numeric(20, 9), data_pgs(id, ipgs)),
unused = convert(numeric(20, 9),
(reserved_pgs(id, dpgs) + reserved_pgs(id, ipgs)) -
(data_pgs(id, dpgs) + data_pgs(id, ipgs)))
select @unreserved = (
select distinct
sum(size *low/1024)
from master.dbo.sysusages , master.dbo.spt_values d
where
dbid = db_id()
and d.number = 1
and d.type = 'E'
and (segmap = 3 or segmap = 7)
having dbid = db_id()
and d.number = 1
and d.type = 'E')
- (select distinct convert(numeric(11, 0), (sum(res_pgs) + @slog_res_pgs) *
(low / 1024)) from #pgcounts)
select
distinct
reserved = convert(numeric(11, 0), (sum(res_pgs) + @slog_res_pgs) *
(low / 1024)),
data = convert(numeric(11, 0), (sum(dpgs) + @slog_dpgs) *
(low / 1024)),
indexes = convert(numeric(11, 0), sum(ipgs) * (low / 1024)),
unused = convert(numeric(11, 0), sum(unused) * (low / 1024)),
unreserved = @unreserved
from #pgcounts
drop table #pgcounts
这一段只包括data的空间
下面是取log空间的
select distinct
sum(size*low/1024)- sum(curunreservedpgs(db_id(), lstart, unreservedpgs)*low/1024) used ,
sum(curunreservedpgs(db_id(), lstart, unreservedpgs)*low/1024) unused
from master.dbo.sysusages , master.dbo.spt_values d
where dbid = db_id()
and d.number = 1
and d.type = 'E'
and (segmap = 4 or segmap = 7)
having dbid = db_id()
and d.number = 1
and d.type = 'E'