简体   繁体   中英

sql server 2005 .mdf .ldf files

我有这两个文件(.MDF和.LDF)如何将它们附加到microsoft sql server以查看其内容?

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.

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM