[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
Published Thursday, July 27, 2006 9:23 PM by Jon Galloway
Filed under: ,

Comments

# re: [SQL] Change Logical Filenames

Very Nice ;)

Friday, July 28, 2006 12:49 AM by Kamran Shahid

# [SQL] Scripting backup and restore all databases on a server (Part 2 - Extra CreditM)

In the first post of this series, I discussed scripting database restore statements. It seems simple

Friday, July 28, 2006 3:55 AM by JonGalloway.ToString()

# Interesting Finds: July 28, 2006

Friday, July 28, 2006 11:22 PM by Jason Haley

# Interesting Finds: July 28, 2006

Friday, July 28, 2006 11:25 PM by Jason Haley

# re: [SQL] Change Logical Filenames

Excellent !. Could not find anybody that knew how to do it !

Tuesday, October 24, 2006 6:22 AM by Nel van Zyl

# re: [SQL] Change Logical Filenames

Fantastic - it's just what I needed!

Tuesday, January 23, 2007 1:05 PM by Susan

# re: [SQL] Change Logical Filenames

Excellent - just spent all morning tyring to figure out how to do this until I came across this link!!

Wednesday, February 14, 2007 8:07 AM by Del

# re: [SQL] Change Logical Filenames

i owe you so much, thanks

Friday, May 18, 2007 5:38 AM by serkan şendur

# My Secure Dot Org » Change Logical Filenames in SQL

Pingback from  My Secure Dot Org » Change Logical Filenames in SQL

Tuesday, June 12, 2007 1:40 PM by My Secure Dot Org » Change Logical Filenames in SQL

# re: [SQL] Change Logical Filenames

Awesome...very useful info.

Wednesday, December 05, 2007 10:33 AM by Girish

# re: [SQL] Change Logical Filenames

I m trying to rename file.......waste 1 hr

its really working

thanks

Wednesday, April 09, 2008 4:12 AM by Sandeep

# re: [SQL] Change Logical Filenames

Exactly what I have been looking for! Resolved my issue right away and enhanced my knowledge! Thanks you so much for keeping the commands there for sharing!

Friday, April 18, 2008 9:58 AM by zqi

# re: [SQL] Change Logical Filenames

I was wondering, if Logical File Name should be uunique to a database?

Saturday, April 26, 2008 9:20 PM by Ankit

# re: [SQL] Change Logical Filenames

This has been bothering me for weeks!  It is now fixed!  Thanks Jon!

Thursday, May 15, 2008 2:23 PM by Alex

# re: [SQL] Change Logical Filenames

Cool. This is what I was looking for :)

Friday, July 04, 2008 10:09 AM by Greg

# re: [SQL] Change Logical Filenames

thanks man..

having a logical name of outbound_tracking was bugging the hell out of me since the database was renamed tracking

Friday, September 12, 2008 1:06 PM by kevin M

# re: [SQL] Change Logical Filenames

Jon - I found this to be very useful. This is the type of stuff they don't show you in books. Thanks a lot for sharing!!

Tuesday, October 07, 2008 11:33 AM by B. Khindri

Leave a Comment

(required) 
(required) 
(optional)
(required)