USE [master] GO ALTER DATABASE DBName SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE DBName SET RECOVERY SIMPLE --简单模式 GO USE DBName GO DBCC SHRINKFILE (N'DBName_log' , 1, TRUNCATEONLY) GO USE [master] GO ALTER DATABASE DBName SET RECOVERY FULL WITH NO_WAIT GO ALTER DATABASE DBName SET RECOVERY FULL --还原为完全模式 GO
懒人处理方式:写个存储过程,处理日志清理,优点:只要复制个数据库名称就行,缺点:只有一个日志文件的数据库可以这么干。
declare @dbname nvarchar(500)='CRM' ---设置数据库名称 declare @dblogname nvarchar(500) declare @exsql nvarchar(500)='use ['+@dbname +'] select @dblogname=name from sys.database_files where type=1';--仅针对一个日志文件数据库,多个日志文件不适用 exec sp_executesql @exsql,N'@dblogname nvarchar(500) output',@dblogname output PRINT '获取日志文件名称:'+@dblogname --------------开始执行日志清理-----其实调用的就是上面的日志清理----------------------- exec('USE [master] ALTER DATABASE ['+@dbname+'] SET RECOVERY SIMPLE WITH NO_WAIT ALTER DATABASE ['+@dbname+'] SET RECOVERY SIMPLE USE ['+@dbname+'] DBCC SHRINKFILE (['+@dblogname+'], 1, TRUNCATEONLY) ---DBCC SHRINKDATABASE(['+@dbname+']) USE [master] ALTER DATABASE ['+@dbname+'] SET RECOVERY FULL WITH NO_WAIT ALTER DATABASE ['+@dbname+'] SET RECOVERY FULL '); print @dbname+'日志清理完成.' --------------日志清理结束-----------------------------------
如果你要Copy请注明来源,谢谢!