SQL2008数据表空间大小查询脚本

--尽量少用触发器,否则数据库增长很快,特别是关于登陆的数据表字段不要用出发器,一周左右能使得数据库增长1G的空间.

--数据库表空间大小查询脚本

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[#Data]') AND type in (N'U'))
DROP TABLE [dbo].[#Data]

create table #Data(name varchar(100),row varchar(100),reserved varchar(100),data varchar(100),index_size varchar(100),unused varchar(100))
 
declare @name varchar(100)
declare cur cursor  for
    select name from sysobjects where xtype='u' order by name
open cur
fetch next from cur into @name
while @@fetch_status=0
begin
    insert into #data
    exec sp_spaceused   @name
    print @name
 
    fetch next from cur into @name
end
close cur
deallocate cur

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[#DataNew]') AND type in (N'U'))
DROP TABLE [dbo].[#DataNew]

create table #DataNew(name varchar(100),row int,reserved int,data int,index_size int,unused int)
 
insert into #dataNew
select name,convert(int,row) as row,convert(int,replace(reserved,'KB','')) as reserved,convert(int,replace(data,'KB','')) as data,
convert(int,replace(index_size,'KB','')) as index_size,convert(int,replace(unused,'KB','')) as unused from #data 
 
select * from #dataNew order by data desc

--select * from mchk_his;
--truncate table mchk_his;
--delete from mchk_his;

上一篇:Java模拟网站登录02【转载】


下一篇:接口自动化框架(java)--5.通过testng.xml生成extentreport测试报告