Renaming mdf and ldf files

  • In my sql server I detached one database and then renamed the names of mdf and ldf files , then when I try to attch the database , it gave me an error.

    In the end I had to put back the original names of the files .

    My question is how to rename the mdf and ldf files.

    Thanks in advance!!

  • I don't believe you can because the files are marked internally in the sysfiles table and they cannot be rename by hand. However I know you can back them up then restore to a different name as the restore writes the new info to the sysfiles table at the time.

     

    You may also be able to use sp_attach_db with the file name change but I am not 100% sure there and you have to detach the current db if you want to retain the db name.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply