I saw this question but it didn't help me.

Is there a simple way to do :

Backup database SomeDatabase 
   to disk ='c:\teste\SomeDatabase.bkp'

configuring the Logical Name?

We have some databases, restored of backups of another database (to follow same structure) and when I use RESTORE FILELISTONLY, it shows me a different name. So the Database TestDBA has the logical name BANK.

  • No, you can't specify the logical file names at backup time (or at restore time). You can restore with move, giving the physical file a proper name, but you'd then have to use ALTER DATABASE to rename the logical files. If you're restoring test copies of databases I don't think this extra step is worth it. – Aaron Bertrand Apr 17 '15 at 13:18
  • Why does it matter what the logical name is for a file? @AaronBertrand is right, there is no point. – Chris Woods Apr 17 '15 at 13:21
  • Thanks @AaronBertrand. the problem is, the developers here are developing a system, using "backup database" and a "restore". During the restore, they were using the database name inside the variable in the with move, but I told him not every time the logical name will be the database name. – Racer SQL Apr 17 '15 at 13:22
  • 1
    Then the problem is the developers there need to not make assumptions about logical file names and write their script correctly. What are they going to do when the database has an extra data file? – Aaron Bertrand Apr 17 '15 at 13:52

The logical file names returned by RESTORE HEADERONLY are those of the source database. You cannot change these logical names during the backup or restore. The backup file always contains the both the original logical and physical file names.

The original logical names may be specified with the MOVE option of RESTORE to relocate/rename the physical files during the restore process. After the restore, you can rename the logical names using ALTER DATABASE:

MODIFY FILE(NAME='Teste_Ferdando_Index', NEWNAME='Teste_Dan_index');

Personally, I avoid including the database name in the logical name to avoid this issue, only including the database name in the physical name. Unfortunately, the database name is often included in the logical name by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.