SqlServer清理資料庫日誌

2021-06-22 12:35:22 字數 1268 閱讀 2442

在sqlserver資料庫資料量提公升和大量的運算元據庫,不免產生很多的資料庫日誌,可以通過sqlserver自帶的作業進行定期的資料庫日誌清理,**如下:

--清空所有資料庫日誌

declare @exec_sql nvarchar(1200),@******_sql nvarchar(1200),@full_sql nvarchar(1200)

declare @db_name varchar(128)

declare @db_count int

select @db_count=count(1) from sys.databases where database_id >4

declare @j int

set @j =1

while @j<=@db_count

begin

select @db_name=name from (select row_number()

over(order by name)rn,name from sys.databases

where database_id >4 )as tmp where rn=@j

set @******_sql=n' use [master] ' + char(10) + char(13)

+'alter database ['+@db_name+'] set recovery ****** with no_wait'

exec sp_executesql @******_sql,n'@db_name varchar(128)',@db_name

set @exec_sql=n'use ['+@db_name+']'+ char(10) + char(13)

+'dbcc shrinkfile (n'''+@db_name+'_log'' , 0, truncateonly)'

exec sp_executesql @exec_sql,n'@db_name varchar(128)',@db_name

set @full_sql =n' use [master] ' + char(10) + char(13)

+'alter database ['+@db_name+'] set recovery full with no_wait'

exec sp_executesql @full_sql,n'@db_name varchar(128)',@db_name

set @j =@j+1

end

sql server 資料庫日誌清理

sql server 資料庫日誌清理 use master goalter database 資料庫名 set recovery with no wait goalter database 資料庫名 set recovery gouse 資料庫名 godbcc shrinkfile n 資料庫日誌檔...

SQL SERVER資料庫清理DB LOG

日誌的邏輯檔名是dbname log,資料庫dbname use dbname backup log dbname with no log 截斷事務日誌 gooption 1 dbcc shrinkfile dbname log,10 收縮事務日誌 go option 2 企業管理器 右鍵你要壓縮的...

sqlserver 資料庫日誌清理

現象 sqlserver的日誌如果過大,收縮起來時間長而且可能會影響效能。用下面的辦法可以消耗很少的資源,而且比日誌收縮要快,簡直是快的不要不要的。缺點是必須停庫操作。一,分離資料庫 a 右鍵單機資料庫 tasks detach b 選中 drop connections 和 update stat...