Clear the log file of your SQL server database
March 28. 2016
0 Comments
- Posted in:
- SQL Server
When you want to clear the log file for your SQL Server database to, for example, use it on a developers pc. The chances are high that the database from the production environment isn't using the 'Simple' recovery model. This means there are log backups, which can have the log file grow enormously.
So first revert the database to simple recovery mode:
Shrink the database log file to a specified target size:
More info can be found here.
So first revert the database to simple recovery mode:
USE master ; ALTER DATABASE [YourDBName] SET RECOVERY Simple ;
Shrink the database log file to a specified target size:
USE [YourDbName];
GO -- Shrink the truncated log file to 1 MB. DBCC SHRINKFILE ([YourLogFileName], 1);
GO
More info can be found here.