Tuesday, October 11, 2016

how to restore MDF file

Resotring MDF file alone need trick.
1. to copy the mdf file login into DB server.
2. Stop the SQL serivice by clicking on servername.
3. copy and paste MDF file on other drive.
4. start the serive in SQL Jobs (Client)

Login in to server where you want to store MDF file alone.
1. Created the database with same name. (for example I named it TestLDFAttach)
USE [master]
GO
ALTER DATABASE [TestLDFAttach] SET EMERGENCY
GO
ALTER DATABASE [TestLDFAttach] SET SINGLE_USER
GO

2. Now stop the SQL Service.

3. Copy and paste MDF in  in SQL server Data folder locaiton
4.Replace the MDF file.

5. Restart the SQL Service.

6. run the follwing comamnd
 USE [master] 

DBCC CHECKDB ([TestLDFAttach], REPAIR_ALLOW_DATA_LOSS) 
GO 
ALTER DATABASE [TestLDFAttach] SET MULTI_USER 
GO 
ALTER DATABASE [TestLDFAttach] SET ONLINE 
GO 

7. compare the database. it iwll same even we recoved with data loss.

No comments: