當數(shù)據(jù)庫的日志文件太大的情況下,SQLServer 2008 以上版本進行數(shù)據(jù)庫日志清理,需要采用的方法如下(執(zhí)行前 將數(shù)據(jù)庫名 改成你需要清理的數(shù)據(jù)名稱)
–1)查詢指定數(shù)據(jù)庫的 <數(shù)據(jù)庫日志文件名稱>? ,通過下面的sql的語句查詢到<數(shù)據(jù)庫日志文件名稱>,替換到下面sql的<數(shù)據(jù)庫日志文件名稱>
USE [數(shù)據(jù)庫名]
GO
SELECT name FROM SYS.database_files WHERE type_desc=’LOG’
–2)執(zhí)行后清理該數(shù)據(jù)庫日志文件
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