Shrink or truncate SQL Server log file

It happens that the SQL Server have a large log file, and you don't need it. Here is the ways to shrink the log file:

 Method 1:

Import the data to the database ( highlight the database->Tasks->Import data  ),

or Export the data from the database ( highlight the database->Tasks->Export data )

Method 2:

Shrink the log file to the desired size, for example, 1MB.  That is, highlight the database->Tasks->Shrink->Files

 set the file size, say, 1MB.

 

Method 3 ( Eliminate the log file completely):

In the SQL Server Management Studio,

  1. Highlight the database-> Tasks->Detach..-> Click OK
  2. Go to log file folder -> rename the testDev_log.ldf to be like testDev_log-aa.ldf,
  3. Highlight Databases->Attach-> Click Add -> add the database testDev, highlight the log file and click the Remove button. This means you only attach testDev.mdf
  4. After this is done, you can verify the contents of the attached database and then delete the log file.

Method 4

USE Site2
GO
DBCC SHRINKFILE('Site2_Log', 1)
BACKUP LOG Site2 WITH TRUNCATE_ONLY
DBCC SHRINKFILE('Site2_Log', 1)
GO

posted @ 2009-05-06 11:03  See Me Fly  阅读(616)  评论(0编辑  收藏  举报