set nocount on
declare @logicalfilename sysname,
@maxminutes int,
@newsize int
use tolldb_ic
-- 要操作的資料庫名
select @logicalfilename = 'tolldb_ic_log' ,
-- 日誌檔名
@maxminutes = 10,
-- limit on time allowed to wrap log.
@newsize = 500
-- 你想設定的日誌檔案的大小(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 < @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
MsSql截斷收縮日誌
backup log cas with truncate only 截斷日誌等同於dump tran 資料庫 with truncate only set nocount on declare logicalfilename sysname,maxminutes int,newsize int us...
快速收縮MSSQL資料庫日誌
快速收縮資料庫只有下面三個步驟 特別注意 請按步驟進行,未進行前面的步驟,請不要做後面的步驟 否則可能損壞你的資料庫.一 開啟查詢分析器,預設資料庫選擇master,然後進行下列操作 1.清空日誌 dump transaction 資料庫名 with no log 2.截斷事務日誌 backup l...
SQL收縮日誌
在sql執行中,有時發現日誌檔案過大,影響的記憶體空間大小,這時我們需要進行sql收縮日誌的操作 1 檢視資料庫的recovery model desc型別 select name,recovery model desc from sys.databases 2 如果是full型別,則修改為 alt...