收缩日志文件夹
-- ========== MSSQL2005 =====================
USE master
go
DECLARE @dbname sysname;
SET @dbname='BSV100';
-- 清空日志
EXEC ('DUMP TRANSACTION ['+@dbname+'] WITH NO_LOG');
-- 截断事务日志:
EXEC ('BACKUP LOG ['+@dbname+'] WITH NO_LOG');
-- 收缩数据库文件(如果不压缩,数据库的文件不会减小
EXEC ('DBCC SHRINKDATABASE(['+@dbname+'])');
-- ========== MSSQL2008 =====================
/*允许 DBCC SHRINKFILE 命令收缩文件,
首先需要通过将数据库恢复模式设置为 SIMPLE 来截断该文件*/
USE CM;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE CM SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 10 MB.
DBCC SHRINKFILE (CM_log, 10); -- sp_helpdb 'cm'
GO
ALTER DATABASE CM SET RECOVERY FULL;
GO
-- ============== 收缩错误日志 ==================
USE master
go
/*数据维护命令,解决ErrorLog文件太大的问题
截断原有的,另起一个新的ErrorLog文件
要执行几次
观察路径C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG
下没有出现大的ERRORLOG文件为止*/
DBCC ErrorLog;