- 1). Create a database in Microsoft SQL Server called 'Demand', Here is the SQL command to issue in a query window, it uses defaults for everything but the database name: create database Demand
- 2). Determine where the MDF and LDF files of the database are actually stored on the hard drive: sp_Helpdb Demand
By default it will be somewhere such as: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data - 3). Detach the MDF and LDF files from the Microsoft SQL Server instance: sp_detach_db Demand
- 4). Open the location where the files are stored and either delete the Demand.LDF file or change its name. This will simulate only having the MDF available to attach.
- 5). Attach the MDF file to the Microsoft SQL server instance by issuing the following command in a query window, change the database name and file path accordingly: EXEC sp_attach_db @dbname = N'Demand',
@filename1 = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Demand.mdf'
You should get a message similar to: File activation failure. The physical file name "c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\Demand_log.LDF" may be incorrect.
New log file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Demand_log.LDF' was created.
The Microsoft SQL Server tried to reattach the default LDF file, but since it was missing the server just created a new log file.
SHARE