Change the logical name of MSSQL database/transaction log files

When a database backup is restored in MSSQL, the physical filenames can be amended during the restore process but the logical names for the source database and transaction log files are kept.
It is a simple step to amend these however…
First, find the current names of the files where <database_name> is the name of the restored DB.

SELECT database_id,
       name, 
       physical_name 
FROM sys.master_files 
WHERE database_id = DB_ID('<database_name')

Now we can modify the names. <database_name> is the name of the restored DB, <current name> is the logical name inherited from the source DB and <desired name> is what you will be changing it to.

ALTER DATABASE <database_name> MODIFY FILE (NAME='<current name>', NEWNAME='<desired name>');
ALTER DATABASE <database_name> MODIFY FILE (NAME='<current name>', NEWNAME='<desired name>');

That’s all there is to it! Hope this helps.

Comments

2 responses to “Change the logical name of MSSQL database/transaction log files”

  1. Cbd Tincture Avatar

    When I started my computer this site was already running. Your post is really worth everyone’s time. I’m continually lookingon the internet for insights that will help me. You must really have a good head resting on your neck.

    1. pobby69 Avatar

      Thanks for the feedback

Leave a Reply

Your email address will not be published. Required fields are marked *