Change logical name to DB files

  • Hello guys.

    I'm wondering how to change the logical name to a DB. I mean the "name" column in this sentence

    select * from sysfiles

    A clear example is when you have the test and production databases in the same server and restore one of them to the other; the name column will keep the old DB name.

    I've reviewed sp_rename% or sp_change% SP's but none of them seem to be helpful.

    Any clue?

  • When you restore your test db you should use the

    WITH MOVE option to rename your files.

    You cannot rename the files of a database.

     

  • And what about taking dettach-rename-reattach? As far as I understand this will leave us with the old "name" too, but without a way to change it :-

    I know to lurk in systables is not recomended, but maybe is this a way?

  • Isn't this done using

    ALTER DATABASE X

    MODIFY FILE (NAME = logical_file_name, NEWNAME = new_logical_name...).

  • Yes, that works!

    Thank you!

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

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