How to purge a SQL Server 2008 database transaction log file ?

TRUNCATE_ONLY switch instead:

USE adatbazisnev
GO
DECLARE @SqlStatement as nvarchar(max)
DECLARE @LogFileLogicalName as sysname
SET @SqlStatement = 'ALTER DATABASE ' + DB_NAME() + ' SET RECOVERY SIMPLE'
EXEC ( @SqlStatement )
SELECT [name], [recovery_model_desc] FROM sys.databases WHERE [name] = DB_NAME()
SELECT @LogFileLogicalName = [Name] FROM sys.database_files WHERE type = 1
DBCC Shrinkfile(@LogFileLogicalName, 1)
SET @SqlStatement = 'ALTER DATABASE ' + DB_NAME() + ' SET RECOVERY FULL'
EXEC ( @SqlStatement )
SET @SqlStatement = 'SELECT [name], [recovery_model_desc] FROM ' + DB_NAME() + '.sys.databases WHERE [name] = ''' + DB_NAME() + ''''
EXEC ( @SqlStatement )

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s