Ron
Ron

Reputation: 51

sql server 2005 .mdf .ldf files

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

Upvotes: 3

Views: 2345

Answers (5)

havana59er
havana59er

Reputation: 432

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.

Upvotes: 0

DenNukem
DenNukem

Reputation: 8284

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'"

Upvotes: 3

MartW
MartW

Reputation: 12538

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.

Upvotes: 0

DOK
DOK

Reputation: 32851

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.

Upvotes: 7

j.a.estevan
j.a.estevan

Reputation: 3097

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.

Upvotes: 1

Related Questions