MS-SQL 清除交易記錄 Transaction Log MS-SQL 清除交易記錄 Transaction Log
  MS-SQL       ez      2012-05-04

在各版本的 MS-SQL 皆有不同,方法如下: SQL 7.0/2000:

BACKUP TRANSACTION DBName WITH TRUNCATE_ONLY DBCC SHRINKFILE(2,0)

  SQL 2005:

BACKUP LOG DBName WITH NO_LOG
DBCC SHRINKFILE(2,0)

  SQL 2008: 必須先將復原模式改為 "簡單" 才能清除,完成之後再將模式改回 "完整"

USE DBName
Alter Database DBName Set Recovery Simple DBCC SHRINKFILE(2,0) Alter Database DBName Set Recovery Full

  SQL 2008 R2:

USE DBName;
GO

-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE DBName
SET RECOVERY SIMPLE;
GO

-- Shrink the truncated log file to 10 MB.
DBCC SHRINKFILE (2, 0);
GO

-- Reset the database recovery model.
ALTER DATABASE DBName
SET RECOVERY FULL;
GO

標籤:   MS-SQL

我要留言