See How You Can Attach an MDF File
SQL Server by default stores its databases in two files, which are as follows:
- MDF File: The MDF file is actually the primary data file, which contains table schemas, tables, and data
- LDF File: The LDF file is the file containing the logs for the database
It is good if you have both files (MDF file and LDF file) attached to the SQL Server instance, but for you, it is possible only to attach the MDF file, and the SQL server will itself create an LDF file for that database.
- Create a database in the SQL Server calling it “Demand”. The command you need to issue in a query Window, which uses defaults for each and everything but the database name: create database Demand
- Find out where the MDF and LDF files are actually stored on the hard drive of your system: sp_Helpdb Demand (By default, they can be stored at the location: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data)
- You have to detach these MDF and LDF files from the Server instance: sp_detach_db Demand
- Now, you should open the location where these files are stored. You can either delete the Demand.LDF file or you can change its name.
- After that, you can attach the MDF file to the MS SQL server instance. You can do this by issuing the following command in a query Window (keep the database name and file path according to your requirement):
XEC sp_attach_db @dbname = N'Demand', @filename1 = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Demand.mdf
SysTools SQL Recovery Software
If you are attaching your database in MDF File and you successfully attached your database in MDF file but, if your database gets corrupt due to some unavoidable reasons then you need to repair that corrupt database, and it’s possible when you have successful SQL MDF database recovery software. To repair or recover your corrupt database of SQL Server you can try SysTools SQL Server Recovery Software with no doubts.



