views:

2410

answers:

4

I need to empty an LDF file before sending to a colleague. How do I force SQL Server to truncate the log?

+4  A: 

In management studio:

  • Right-click the database, choose properties, then options.
  • Make sure "Recovery model" is set to "Simple", not "Full"
  • Click Ok
  • Right-click the database again, choose tasks -> shrink files
  • Change file type to "log"
  • Click ok.

Alternatively, the SQL to do it:

 ALTER DATABASE mydatabase SET RECOVERY SIMPLE
 DBCC SHRINKFILE (mydatabase_Log, 1)

Ref: http://msdn.microsoft.com/en-us/library/ms189493.aspx

Blorgbeard
+2  A: 

backup log logname with truncate_only followed by a dbcc shrinkfile command

SQLMenace
+9  A: 

if I remember well... in query analyzer or equivalent:

BACKUP LOG  databasename  WITH TRUNCATE_ONLY

DBCC SHRINKFILE (  databasename_Log, 1)
ila
This is definitely better than setting the database recovery model to SIMPLE (as in Blorgbeard's answer) because if your recovery model is FULL, you have it set that way for a reason.
Scott Whitlock
A: 

+1 to ila's answer.

(I've run out of votes today)

GateKiller