如何检测数据库的容量(100分)

  • 主题发起人 主题发起人 吴鸣
  • 开始时间 开始时间

吴鸣

Unregistered / Unconfirmed
GUEST, unregistred user!
请问一下,我如何能知道一个database的现有容量。是否有这方面的sql语句,
delphi是否有控件,能够得到,我该如何去做,对了还有,若象进行增量备份
该如何去做,恢复时是否有问题,可以按照全面恢复和选择性恢复这两种进行
其sql语句怎麽写
 
什么数据库?
可以用sp_spaceused
 
sql server 7.0 和msde 我看了sp_spaceused的帮助,其中有这麽一条,如果不指出
table name,其将反回两个数据集,在query中好象不能处理两个数据集,但是,我想
得到有关库的整体使用情况,我该怎麽办,delphi里有没有处理多数据集的方法
sp_spaceused [[@objname =] 'objname']
[,[@updateusage =] 'updateusage']

Arguments
[@objname =] 'objname'
Is the name of the table for which space usage information (reserved and allocated space) is requested. objname is nvarchar(776), with a default of NULL.
[@updateusage =] 'updateusage'
Indicates whether or not DBCC UPDATEUSAGE should be run within the database (when no objname is specified) or on a specific object (when objname is specified). Values can be true or false. updateusage is varchar(5), with a default of FALSE.
Return Code Values
0 (success) or 1 (failure)

Result Sets
If objname is omitted, two result sets are returned.
 

这是我以前写的一段简化的等同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'

 
如果是oracle,怎么办?
 
接受答案了.
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
900
SUNSTONE的Delphi笔记
S
后退
顶部