Sql Server 2008 R2 清空数据库中ldf日志文件

时间:2021-12-14 13:51:53
/************************************************************
 * Sql Server 2008 R2 清空数据库中ldf日志文件
 * 将TestDB替换为您要操作的数据库即可
 ************************************************************/
USE [master]
ALTER DATABASE [TestDB] 
SET RECOVERY SIMPLE WITH NO_WAIT
ALTER DATABASE [TestDB] 
SET RECOVERY SIMPLE
GO
USE [TestDB]
DECLARE @logname VARCHAR(150)
SELECT @logname = NAME
FROM   sys.database_files
WHERE  NAME LIKE'%log'
DBCC SHRINKFILE(@logname, 11, TRUNCATEONLY)
GO
USE [master]
ALTER DATABASE [TestDB]
SET RECOVERY FULL WITH NO_WAIT
ALTER DATABASE [TestDB] 
SET RECOVERY FULL
GO