清除sql server日志

DECLARE @Sql NVARCHAR(max)
DECLARE @dbname NVARCHAR(50)
SET @dbname='GuangDong';--设置数据库名称

SET @Sql='USE ['+@dbname+']
ALTER DATABASE ['+@dbname+']
SET RECOVERY SIMPLE;
DECLARE @fileId INT
SELECT @fileId=file_id FROM sys.database_files WHERE type=1
DBCC SHRINKFILE (@fileId,1)
ALTER DATABASE ['+@dbname+']
SET RECOVERY FULL;
DBCC SHRINKDATABASE(['+@dbname+'],TRUNCATEONLY)'
EXEC sys.sp_executesql @Sql

 

posted @ 2022-04-28 09:13  随便取个名字算了  阅读(19)  评论(0编辑  收藏  举报