[SQL] Change Logical Filenames

A little while ago, we deployed some really great sites built on the DotNetNuke platform. We started with a base DNN install, worked for several months, and ended up with a really nice suite of sites. Along the way, we renamed the databases, but the logical database names remained DotNetNuke_Data and DotNetNuke_Log. We looked into changing the logical names, but came up empty.

The difference between database and logical names was a problem for two reasons:

  1. While it worked well, it's a rough edge on an otherwise highly polished project. Anyone working on the database sees logical filenames that don't match the database name. That has absolutely no impact to how well the application works, but it always bugged me.
  2. It's harder to script backup / restore operations when the database logical names don't match the database name. For example, I previously posted a script to FTP download and restore a MSSQL database backup, and I was frustrated that I needed to specify the database logical name.

Well, it turns out that I just didn't look hard enough. ALTER DATABASE allows you to rename a file using NEWNAME:

USE MASTER
GO
ALTER DATABASE MegaCorp
MODIFY FILE
(NAME = DotNetNuke_Data, NEWNAME='MegaCorp_Data')
GO

ALTER DATABASE MegaCorp
MODIFY FILE
(NAME = DotNetNuke_Log, NEWNAME='MegaCorp_Log')
GO

12 Comments

Comments have been disabled for this content.