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.
As you have said, have .mdf file only. You can still attach your database without ldf file. You just need to run following commands: 

Method 1:

```
EXEC sp_attach_single_file_db @dbname='Database_Name',
@physname=N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Database_Name.mdf'
GO

```

As suggested above.

Method 2:

```
CREATE DATABASE Database_Name ON
(FILENAME =N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Database_Name.mdf')
FOR ATTACH_REBUILD_LOG
GO

```

It will create log file for you.