mssql 日志清除 sql语句
日志清除
set nocount on
declare @logicalfilename sysname,
@maxminutes int,
@newsize intuse tablename -- 要操作的名
select @logicalfilename = 'tablename_log', -- 日志文件名
@maxminutes = 10, -- limit on time allowed to wrap log.
@newsize = 1 -- 你想设定的日志文件的大小(m)
setup / initialize
declare @originalsize int
select @originalsize = size
from sysfiles
where name = @logicalfilename
select 'original size of ' + db_name() + ' log is ' +
convert(varchar(30),@originalsize) + ' 8k pages or ' +
convert(varchar(30),(@originalsize*8/1024)) + 'mb'
from sysfiles
where name = @logicalfilename
create table dummytrans
(dummycolumn char (8000) not null)declare @counter int,
@starttime datetime,
@trunclog varchar(255)
select @starttime = getdate(),
@trunclog = 'backup log ' + db_name() + ' with truncate_only'
dbcc shrinkfile (@logicalfilename, @newsize)
exec (@trunclog)
-- wrap the log if necessary.
while @maxminutes > datediff (mi, @starttime, getdate()) -- time has not expired
and @originalsize = (select size from sysfiles where name = @logicalfilename)
and (@originalsize * 8 /1024) > @newsize
begin -- outer loop.
select @counter = 0
while ((@counter begin -- update
insert dummytrans values ('fill log') delete dummytrans
select @counter = @counter + 1
end
exec (@trunclog)
end
select 'final size of ' + db_name() + ' log is ' +
convert(varchar(30),size) + ' 8k pages or ' +
convert(varchar(30),(size*8/1024)) + 'mb'
from sysfiles
where name = @logicalfilename
drop table dummytrans
set nocount off
推荐阅读
-
SQLServer日志清空语句(sql2000,sql2005,sql2008)
-
SQL语句实现SQL Server 2000及Sql Server 2005日志收缩(批量)
-
解析:清除SQL被注入恶意病毒代码的语句
-
清除SQL SERVER错误日志出现操作系统错误的解决方法
-
SQL Server 数据库清除日志的方法
-
mssql sql语句过滤百分号的方法分享
-
mssql server .ldf和.mdf的文件附加数据库的sql语句
-
mssql 两表合并sql语句
-
mssql函数DATENAME使用示例讲解(取得当前年月日/一年中第几天SQL语句)
-
t-sql/mssql用命令行导入数据脚本的SQL语句示例