SQL Server2008事务日志收缩同SQL Server2005和2000大不相同了
一.在SQL Server2000或SQL Server2005中收缩/清空事务日志的方法:
压缩日志:
--先备份数据库
backup database dbname to disk='xxxx.bak'
--截断事务日志
backup log 数据库名 with no_log
go
--收缩数据库
dbcc shrinkdatabase(数据库名,10)
go
清空日志:
DUMP TRANSACTION 数据库名 WITH NO_LOG
收缩数据库文件
企业管理器-右键你要压缩的数据库-所有任务-收缩数据库-收缩数据文件-输入能够收缩到的最小值-确定
DBCC SHRINKFILE (<log_filename>,10)
二.SQL Server2008事务日志的收缩方法:
1.
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
2.
BACKUP LOG xxdb to disk='x:\work\1.bak'
DBCC SHRINKFILE (xxdb_log,10)
GO
--里面的x:\work是随意设置的。当然也可以收缩到比如5M或1M。
BACKUP LOG <db_name> to disk=<'backupfilename'>
DBCC SHRINKFILE (<log_filename>,10)
GO