sql
1 --清除日誌:sql server清除日誌語句,再也不用為龐大的日誌佔硬碟而煩惱了......2 declare @logicalfilename sysname,
3 @maxminutes int,
4 @newsize int
5 use database --******** 要操作的資料庫名********
6 select @logicalfilename = '
database_log
', -- ********日誌檔名********
7 @maxminutes = 10, -- limit on time allowed to wrap log.
8 @newsize = 20 -- ********你想設定的日誌檔案的大小(m)********
9 -- setup / initialize
10 declare @originalsize int
11 select @originalsize = size
12 from sysfiles
13 where name = @logicalfilename
14 select '
original size of
' + db_name() + '
log is
' +
15 convert(varchar(30),@originalsize) + '
8k pages or
' +
16 convert(varchar(30),(@originalsize*8/1024)) + 'mb'
17 from sysfiles
18 where name = @logicalfilename
19 create table dummytrans(dummycolumn char (8000) not null)
20 declare @counter int,
21 @starttime datetime,
22 @trunclog varchar(255)
23 select @starttime = getdate(),
24 @trunclog = '
backup log
' + db_name() + '
with truncate_only
'25 dbcc shrinkfile (@logicalfilename, @newsize)
26 exec (@trunclog)
27 -- wrap the log if necessary.
28 while @maxminutes > datediff (mi, @starttime, getdate()) -- time
29 and @originalsize = (select size from sysfiles where name =
30 @logicalfilename) and (@originalsize * 8 /1024) > @newsize
31 begin -- outer loop.
32 select @counter = 0
33 while ((@counter < @originalsize / 16) and (@counter < 50000))
34 begin -- update
35 insert dummytrans values ('
fill log
')
36 delete dummytrans
37 select @counter = @counter + 1
38 end
39 exec (@trunclog)
40 end
41 select '
final size of
' + db_name() + '
log is
' +42 convert(varchar(30),size) + '
8k pages or
' +
43 convert(varchar(30),(size*8/1024)) + 'mb'
44 from sysfiles
45 where name = @logicalfilename
46 drop table dummytrans
47 set nocount off
SQL SERVER 清除日誌
1.在sql2008中清除日誌就必須在簡單模式下進行,等清除動作完畢再調回到完全模式。2.這裡的dbname log 可以通過以下查詢 use dbname goselect file id,name from sys.database files use master goalter databa...
sqlserver清除日誌 驗證
1.dump transaction database name with no log 收縮資料庫是還真是必須的加上 2.backup log database name with no log 3.收縮資料庫檔案 如果不壓縮,資料庫的檔案不會減小 企業管理器 右鍵你要壓縮的資料庫 所有任務 收縮...
使用語句清除sqlserver資料庫日誌檔案
修改其中的3個引數 資料庫名,日誌檔名,和目標日誌檔案的大小 執行即可 set nocount on declare logicalfilename sysname,maxminutes int,newsize intuse tablename 要操作的資料庫名 select logicalfile...