Skip to content

Instantly share code, notes, and snippets.

@gildotdev
Created January 27, 2015 02:18
Show Gist options
  • Save gildotdev/d170dd5423fbd6a2ab5c to your computer and use it in GitHub Desktop.
Save gildotdev/d170dd5423fbd6a2ab5c to your computer and use it in GitHub Desktop.
Shrinking a log file to a specified target size The following example shrinks the log file in the AdventureWorks2008R2 database to 1 MB. To allow the DBCC SHRINKFILE command to shrink the file, the file is first truncated by setting the database recovery model to SIMPLE.
USE ExampleDB;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE ExampleDB
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (ExampleDB_Log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE ExampleDB
SET RECOVERY FULL;
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment