SQL2008 以上版本日志清理
- 建議對需要做日志清理的數(shù)據(jù)庫,先做 數(shù)據(jù)庫備份
- 數(shù)據(jù)庫可能因為日志文件大而造成空間不足(先查看數(shù)據(jù)庫文件的日志文件大?。?/li>
- 運行腳本獲取所需清理數(shù)據(jù)庫的日志名稱 (修改紅色部分數(shù)據(jù)庫名稱)
|
|
–查詢指定數(shù)據(jù)庫的 ,通過下面的sql的語句查詢
USE [數(shù)據(jù)庫名]
GO
SELECT name FROM SYS.database_files WHERE type_desc=’LOG’ |
|
|
|
USE [master]
GO
ALTER DATABASE [數(shù)據(jù)庫名] SET RECOVERY SIMPLE WITH NO_WAIT
GO
ALTER DATABASE [數(shù)據(jù)庫名] SET RECOVERY SIMPLE
GO
USE [數(shù)據(jù)庫名]
GO
DBCC SHRINKFILE (N’數(shù)據(jù)庫日志文件名稱’ , 0,TRUNCATEONLY)
GO
USE [master]
GO
ALTER DATABASE [數(shù)據(jù)庫名] SET RECOVERY FULL WITH NO_WAIT
GO
ALTER DATABASE [數(shù)據(jù)庫名] SET RECOVERY FULL
GO |
|
按腳本獲取到的 數(shù)據(jù)庫日志文件名稱 – 覆蓋; 及修改 數(shù)據(jù)庫名
粘貼代碼到 SQL的查詢分析器進行運行
運行后,日志文件將清空