`
阿尔萨斯
  • 浏览: 4184423 次
社区版块
存档分类
最新评论

检查SQL Server事务日志大小

 
阅读更多
<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe>

最近开始接手SQL Server数据库管理了,每天都要一个一个检查事务日志大小。于是请同事写了一个检查事务日志大小的SQL脚本,列出事务日志超过1G的数据库,顺便也学习学习,自从转入运维后就很少接触SQL了,现在又要拾起来了。


setnocounton

declare@namesysname
declare@SQLnvarchar(600)

createtable#databases(
DATABASE_ID
intNOTNULL,
size
intNOTNULL)

declarec1cursorfor
selectnamefrommaster.dbo.sysdatabases
wherehas_dbaccess(name)=1

openc1
fetchc1into@name

while@@fetch_status>=0
begin
select@SQL='insertinto#databases
select
'+convert(sysname,db_id(@name))+',sizefrom'
+QuoteName(@name)+'.dbo.sysfileswherefileid=2'
execute(@SQL)
fetchc1into@name
end

deallocatec1

select
DATABASE_NAME
=db_name(DATABASE_ID),
LOG_SIZE
=cast(round((CEILING(size*8/1024)+1)/1024,3)asvarchar(20))+'G'--(G)
from#databases
wheredb_name(DATABASE_ID)notin('master','model','msdb','pubs','Northwind','tempdb')
andround((CEILING(size*8/1024)+1)/1024,3)>=1
orderby1

droptable#databases



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics