in
Eric Vaillancourt on SQL Server...

MS SQL Admin

How to Attach a database without a transaction log file (.ldf)

Bookmark and Share

If you ever lose the drive that contains your log file, your database will become suspect and will stop working.

 

clip_image002

 

Notice that you cannot expand the database.  If you do, you will get an error message.

You do not need to restore the backup in such a crash.  If you do, you will lose everything since your last BACKUP.  All you have to do is to detach the database and reattach it without the log.  SQL Server 2005 does allow you to do this. You can reattach the database by following these simple steps:

 

  1. first, you need to detach the suspect database:

clip_image004

 

The “detach database” dialog appears, click ok.

 

clip_image006

 

You might get an error just ignore it and the database will be detached.  You will have to refresh the database list to remove your database from the list.

 

  1. Right-click on Databases and select Attach

 

clip_image008

 

The “attach databse” dialog appears.  Click on the “Add” button on locate your mdf file.

 

clip_image010

 

  1. Under database details, select the .LDF file and click the Remove button.

 

clip_image012

 

By doing this, you are telling SQL Server to create a new log file.

 

  1. Click OK.  The database will be attached with a new logfile.

 

Another way would have been to use the CREATE DATABASE with the FOR ATTACH command:

 

USE [master]

GO

CREATE DATABASE [Prod_db] ON

( FILENAME = N'C:\data\prod_db.mdf' )

FOR ATTACH

GO




Hope this helps,

 

Eric Vaillancourt

www.sqlprof.com

 

 

Comments

 

maxim said:

many thanks

so simple

other described ways are so stupid

April 20, 2008 4:11 PM
 

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

April 22, 2008 7:21 AM
 

Erked said:

Great help!

May 8, 2008 10:46 AM

About Eric Vaillancourt

Eric Vaillancourt possède plus de vingt ans d'expérience en programmation de base de données et en gestion de projets. Depuis une dizaine d’années, il se spécialise en optimisation des performances et en coaching d’administrateurs de bases de données. Il a occupé des postes de haute direction dans le secteur privé, principalement dans des firmes technologiques. Il a eu l'occasion de gérer plusieurs projets liés au développement des affaires et aux changements organisationnels.
©2008 SQLProf.com & Eric Vaillancourt
Powered by Community Server (Non-Commercial Edition), by Telligent Systems