Skip to content

Change the logical name of MSSQL database/transaction log files

04/10/2016

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.

Advertisements

From → SQL Server

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: