Restore As

  • In creating a test environment by restoring a database as the test database, I've noticed the File Name (in Database Properties) changes to the file name of the restored database. So, restoring db ABC to db XYZ causes the File Name to become ABC_Data.mdf in the XYZ company.

    Am I doing something wrong? When I try to rename the File Name during the restore process, the restore fails, saying the file name is not associated with the database.?.

    Will the file name change create problems?

    TIA

    Dave

  • Get the logical filenames by running

    
    
    RESTORE FILELISTONLY FROM...

    Then restore those logical files to new physical files, e.g.:

    
    
    RESTORE DATABASE XYZ
    FROM DISK = 'e:\mssql\backup\abc.bak'
    WITH MOVE 'ABC' TO 'e:\mssql\data\XYZ.mdf',
    MOVE 'ABC_log' TO 'd:\mssql\tranlogs\XYZ_log.ldf'

    --Jonathan



    --Jonathan

  • Thanks, but either way, after the restore, the File Name (right-click db, choose properties and then click Data Files or Transaction Log) will show the ABC.mdf File Name instead of the XYZ.mdf File Name. The Location shows correctly as e:\mssql\data\XYZ.mdf. This is what I find confusing.

  • I now suspect you're writing about the logical file name. It's very confusing to have used logical names like "ABC_Data.mdf", so please forgive me for my assumption.

    Use ALTER DATABASE to change logical file names:

    
    
    ALTER DATABASE XYZ
    MODIFY FILE (NAME = 'ABC_Data.mdf', NEWNAME = 'XYZ_Data')

    ALTER DATABASE XYZ
    MODIFY FILE (NAME = 'ABC_Log', NEWNAME = 'XYZ_Log')

    --Jonathan



    --Jonathan

  • That did the trick. Thanks and sorry for being the confusing type.

Viewing 5 posts - 1 through 4 (of 4 total)

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