--日志文件收缩至多少M
DECLARE @DBLogSise AS INT
SET @DBLogSise=0
--查询出数据库对应的日志文件名称
DECLARE @strDBName AS NVARCHAR(500)
DECLARE @strLogName AS NVARCHAR(500)
DECLARE @strSQL AS VARCHAR(1000) SELECT
@strLogName=B.name,
@strDBName=A.name
FROM master.sys.databases AS A
INNER JOIN sys.master_files AS B
ON A.database_id = B.database_id
WHERE A.database_id=DB_ID() SET @strSQL='
--设置数据库恢复模式为简单
ALTER DATABASE ['+@strDBName+'] SET RECOVERY SIMPLE;
--收缩日志文件
DBCC SHRINKFILE ('''+@strLogName+''' , '+CONVERT(VARCHAR(20),@DBLogSise)+');
--恢复数据库还原模式为完整
ALTER DATABASE ['+@strDBName+'] SET RECOVERY FULL '
exec(@strSQL)
1.在数据库中执行上面的存储过程名字为:usp_p_delDBLog
2.然后再执行 EXEC dbo.usp_p_delDBLog @DBLogSise = 0 (收缩至多少M)