This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Sharing another interesting interview question in the category of SQL Server Database Backup and Restore.
The question is: Can we restore the only data file (.mdf file) from the backup of SQL Server.
The answer is: Yes, we can restore only .mdf file from the backup of SQL Server (.bak file)
How?
First get the file id from the backup file:
execute below RESTORE and search fileID for the data file (.mdf file)
In my case, fileID =1
1 |
RESTORE FILELISTONLY FROM DISK = 'D:\SQL Backup\TestBackup.bak' |
Use fileID for restoring only that file data file:
1 2 3 4 |
RESTORE DATABASE TestBackupFROM DISK = 'D:\SQL Backup\TestBackup.bak' WITH FILE = 1, RECOVERY |
Now, ready for Next Question:
Question is: Can I bring the database into the ONLINE state without database log files?
Answer is: No, not possible
If you notice the above RESTORE DATABASE, I wrote RECOVERY which will force SQL Server to rebuild the transaction log and will bring the database in ONLINE state.
All the best!
Leave a Reply