在SQL SERVER 2008 中 BACKUP LOG WITH TRUNCATE_ONLY 已不再被支持,要收缩数据库日志,首先需要通过将数据库恢复模式设置为 SIMPLE 来截断该文件。语句如下:
USE DATABASENAME;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE DATABASENAME
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (DATABASENAME_Log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE DATABASENAME
SET RECOVERY FULL;
GO要收缩已做镜像的数据库的日志文档,用
USE DATABASENAME;
GO
BACKUP LOG DATABASENAME TO DISK='文件路径.'
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (DATABASENAME_Log, 1);
GO
USE DATABASENAME;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE DATABASENAME
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (DATABASENAME_Log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE DATABASENAME
SET RECOVERY FULL;
GO
USE DATABASENAME;
GO
BACKUP LOG DATABASENAME TO DISK='文件路径.'
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (DATABASENAME_Log, 1);
GO