views:

261

answers:

5

I have those 2 files (.MDF and .LDF) how could i attach them to microsoft sql server in order to see their content ?

A: 

Those files represent an existing SQL Server DB, so are irrelevant if you want to create a new one.

If you want to work with them or create a new DB, places to start would be with a download of either SQL Server 2008 Express or SQL Server 2005 Express, both free.

EDIT : Since you already have SQL Server, DOK's answer is best.

CodeByMoonlight
I already have sql server installed i want to attach them to it,
Ron
You didn't say that in the original question.
CodeByMoonlight
+1  A: 

Install if you have not do it yet, the sql engine, then using the sql management studio you can use the "Attach" utility to create a database with your files. The attach menu is in the submenu right-click in the server node.

j.a.estevan
+6  A: 

In Management Studio, in Object Explorer, right-click on the Databases folder.

Choose Attach...

At the top of the section titled "Databases to attach", click the Add button.

In the displayed folders and files, navigate to your .mdf file and click on it.

Click OK.

That's all you have to do.

DOK
What about the ldf ?
Ron
The LDF should be picked up automatically once you add the MDF
CodeByMoonlight
+1  A: 

Execute this command from SQL command line (such as query analyzer). Replace AdventureWorks with the name you got.

EXEC sp_attach_db @dbname = N'AdventureWorks', @filename1 = N'C:\AdventureWorks_Data.mdf', 
  @filename2 = N'C:\AdventureWorks_log.ldf';

If you don't have query analyzer handy run this from windows command prompt:

 osql -E -S.\sqlexpress -Q"EXEC sp_attach_db @dbname = N'AdventureWorks', @filename1 = N'C:\AdventureWorks_Data.mdf', @filename2 = N'C:\AdventureWorks_log.ldf'"
DenNukem
A: 

Whoever gave you those two files is doing it wrong. It is a much better practice to create a backup of a database and restore the backup to a new or existing server/instance/database.

havana59er