WEB开发网
开发学院数据库MSSQL Server Sql Server 性能分析3 –数据库大小,数据库表大小... 阅读

Sql Server 性能分析3 –数据库大小,数据库表大小综合性分析

 2009-09-05 00:00:00 来源:WEB开发网   
核心提示: /* 当前的数据库大小与昨天的数据库大小做比较得来*/Create Procedure [dbo].[Proc_DBA_Database_Size_Grow]asselect date_time, database_name, db_size, size_type from TB_DBA_Dat

/* 当前的数据库大小与昨天的数据库大小做比较得来*/

Create Procedure [dbo].[Proc_DBA_Database_Size_Grow]
as
select date_time,
       database_name,
       db_size,
       size_type
from TB_DBA_Database_Size
where database_name = 'InsiteProdDG'
and convert(varchar(10),date_time,120)=convert(varchar(10),getdate(),120)
union all
(select date_time,
       database_name,
       db_size*-1,
       size_type
from TB_DBA_Database_Size
where database_name = 'InsiteProdDG'
and convert(varchar(10),date_time,120)=convert(varchar(10),dateadd(day,-1,getdate()),120)
)

------获取数据库表增长大小----

/* 当前的数据库表大小与昨天的数据库表大小做比较得来*/

Create  Procedure [dbo].[Proc_DBA_MES_Table_Grow]
as
select convert(varchar(20),getdate(),120) as date_time,
       name,
       sum(rows) as rows,
       sum(reserved) as reserved,
       sum(data) as data,
       sum(index_size) as index_size,
       sum(unused) as unused,
       'KB' as Size_Type 
from
(select * from
(select top 10 
       name,
       cast(rows as int) as rows,      
       cast(left(reserved,len(reserved)-2) as int) as reserved,
       cast(left(data,len(data)-2)as int) as data,
       cast(left(index_size,len(index_size)-2) as int)  as index_size,
       cast(left(unused,len(unused)-2) as int)  as unused
from TB_DBA_Database_Table_Size
where convert(varchar(10),date_time,120)=convert(varchar(10),getdate(),120)
order by cast(rows as int) desc) t
union
select
       name,
       rows*-1 as rows,
       left(reserved,len(reserved)-2) *-1 as reserved,
       left(data,len(data)-2) *-1 as data,
       left(index_size,len(index_size)-2) *-1 as index_size,
       left(unused,len(unused)-2) *-1 as unused
from TB_DBA_Database_Table_Size
where convert(varchar(10),date_time,120)=convert(varchar(10),dateadd(day,-1,getdate()),120)
and name in(
select top 10 name
from TB_DBA_Database_Table_Size
where convert(varchar(10),date_time,120)=convert(varchar(10),getdate(),120)
order by cast(rows as int) desc)
) x
group by name
order by 3 desc

上一页  1 2 3 

Tags:Sql Server 性能分析

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接