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.
Leave a Reply