Question: I have a `.MDF` file and no `.LDF` files for a database created in SQL Server 2005. When I try to attach the `.MDF` file to a different SQL Server, I get the following error message.

I would like to accomplish any one of the following options:

Attach the database without data loss (unlikely but would save me some time).
Attach the database with data loss (whatever transactions were open are lost).
Recover the schema only (no data) from the `.MDF` file.

What SQL commands can I try to get my database going again?

Answer: 
You can use [sp\_attach\_single\_file\_db](https://msdn.microsoft.com/en-us/library/ms174385(v=sql.90).aspx) or the newer version [CREATE DATABASE database\_name FOR ATTACH\_REBUILD\_LOG](https://msdn.microsoft.com/en-us/library/ms176061(v=sql.90).aspx). In both cases it will create a new log file for you.

Unfortunately because you have no log you will not be able to recover anything that has not been committed. It is also a good idea to run a DBCC CHECKDB afterwards to make sure there is no other damage.
Here are details that cover parts 2) and 3) in case re-creating log doesn’t work which can happen if MDF file is corrupted.

You can recover data and structure only by reading MDF file with some third party tool that can de-code what’s written as binary data but even with such tools you can’t always do the job completely.

In such cases you can try SQL Server Restore Toolbox. From what I know this is the only tool that can do this kind of job but it’s quite expensive.

> 
> <http://www.sqlserver.restoretools.com/>
> 
> 
> 

Much better idea is to try to recover these from any old backups if you have any.