Wednesday 11 April 2012

Shrink database when log is full

DECLARE @DatabaseName VARCHAR(50);
SET @DatabaseName = 'DatabaseName'

SELECT name, recovery_model_desc, log_reuse_wait_desc
FROM sys.databases
WHERE name = @DatabaseName




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, 2);

GO

No comments:

Post a Comment