In SQL SERVER 2008, BACKUP Log with TRUNCATE_ONLY is no longer supported, and to shrink the database log, you first need to truncate the file by setting the database recovery mode to simple.
The statements are as follows:
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_log, 1);
GO
--Reset the database recovery model.
ALTER DATABASE DATABASENAME SET RECOVERY full;
GO
It can also be done through a graphical interface.
By backing up the log first, and then shrinking the log file, the following:
Back database mydb to disk= ' Mydb_bak ';
DBCC SHINKFILE (mydb_log,10);--Shrink to 10m
Error:
[Cause:com.microsoft.sqlserver.jdbc.SQLServerException: The transaction log for database ' RISKDB ' is full. To find out why the space in the log cannot be reused,
See the Log_reuse_wait_desc column in sys.databases. ]
Select Name,log_reuse_wait_desc from sys.databases
----found that the LOG_REUSE_WAIT_DESC for this database in the results is replication to indicate that the log file cannot be compressed because replication
ALTER DATABASE RISKDB set recovery simple
Use RISKDB
DBCC SHRINKFILE (' Riskdb_log ', 10)
ALTER DATABASE RISKDB set recovery full
----
SQL Server 2008 Shrink Log