I moved my database files. When I go attach the MDF file by itself, SQL Server will tell me that it can't find the log files. How do I go about asking the MDF what files it is expecting before attaching it?
More background information: I have a bunch of SAN backup volumes. I attached them to Windows through iSCSI, and now half the drive letters are messed up. Moreover, I multiple volumes should be mapped to the save drive letter, so I can't restore the correct drive letters.
I know that the files are all there, but I don't know how many and which LDF/NDFs I should be attaching with each MDF.
Best Answer
There's no way to find those files with a detached database .mdf. As Aaron suggests, you can create the database with
ATTACH_REBUILD_LOG
. Another option is if you have an "old" backup file of the database, you can useRESTORE FILELISTONLY
to interrogate the backup file for the state of the database files at the time of that backup. This will give you a starting point to track down your files.Edit Because I like Powershell, here's a script that will read through all the full backup files in a directory and build an attachdbs.sql in your Documents folder: