--清除日誌:
declare @logicalfilename sysname,
@maxminutes int,
@newsize int
use szwzcheck -- 要操作的資料庫名
select @logicalfilename = 'szwzcheck_log', -- 日誌檔名
@maxminutes = 10, -- limit on time allowed to wrap log.
@newsize = 20 -- 你想設定的日誌檔案的大小(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
and @originalsize = (select size from sysfiles where name =
@logicalfilename) and (@originalsize * 8 /1024) > @newsize
begin -- outer loop.
select @counter = 0
while ((@counter < @originalsize / 16) and (@counter < 50000))
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
--把szwzcheck換成你資料庫的名字即可,在查詢分析器裡面執行。
--收縮日誌:企業管理器--所有任務--收縮資料庫--檔案--選日誌檔案收縮
清除日誌和收縮日誌
清除日誌 declare logicalfilename sysname,maxminutes int,newsize int use szwzcheck 要操作的資料庫名 select logicalfilename szwzcheck log 日誌檔名 maxminutes 10,limit o...
ms sql收縮日誌
set nocount on declare logicalfilename sysname,maxminutes int,newsize int use tolldb ic 要操作的資料庫名 select logicalfilename tolldb ic log 日誌檔名 maxminutes ...
SQL收縮日誌
在sql執行中,有時發現日誌檔案過大,影響的記憶體空間大小,這時我們需要進行sql收縮日誌的操作 1 檢視資料庫的recovery model desc型別 select name,recovery model desc from sys.databases 2 如果是full型別,則修改為 alt...