Monday, November 22, 2021

SQL Server - Deleting the contents from log file

 You can shrink the log with the following Statements:

USE [MyDatabase]
GO
ALTER DATABASE [MyDatabase] SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE([MyDatabase_log], 1)
ALTER DATABASE [MyDatabase] SET RECOVERY FULL WITH NO_WAIT
GO
This snippet can be found on various sites in the net, but be aware that it's not a good practice to kill the log like this because of recovery. After doing this, you can only recover your database to the last full or full+incremental backup.

No comments: