Solved

How to rename MSSQL DB Permanently After Restore?

Posted on 2013-11-05
5
312 Views
Last Modified: 2013-11-10
I am splitting my database into multiple databases and trying to maintain existing schemas and data.
I need to RESTORE an MSSQL  database 2 or more times and rename it permanently.
I need the names of the physical files to change and during this rename process.
How is this best achieved?
SQL2012
0
Comment
Question by:XGIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:mikeyd234
ID: 39626144
There are several ways to do the rename, however to rename the physical database files at operating system level you will have to take the database offline

1. Use SSMS to take the database Offline (right-click on Database, select Tasks, Take Offline), change the name of the files at the OS level and then Bring it Online.

2. You could Detach the database, rename the files and then Attach the database pointing to the renamed files to do so.

3. You could Backup the database and then restore, changing the file location during the restore process.

4. using T SQL

ALTER DATABASE databaseName SET OFFLINE
GO


ALTER DATABASE databaseNAme MODIFY FILE (NAME =db, FILENAME = 'C:\Program
Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\db.mdf')
GO


--if changing log file name
ALTER DATABASE  databaseNAme MODIFY FILE (NAME = db_log, FILENAME =
'C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\db.ldf')
GO


ALTER DATABASE databaseName SET ONLINE
GO


Easier though to just take it offline and use windows explorer to browse to the DB mdf files and rename. (option 1)

Thanks
0
 
LVL 7

Author Comment

by:XGIS
ID: 39626157
Hello mikeyd234... thats the same page as I am on.  I will delete it all and try it again from restore.  It wont come back online right now because it is still looking for old paths. etc
0
 
LVL 3

Expert Comment

by:mikeyd234
ID: 39626158
Try detach the database, then reattach specifying the new file names
0
 
LVL 7

Accepted Solution

by:
XGIS earned 0 total points
ID: 39626162
My solution was to Restore and Rename the database to a new name then.  Then click on files and change the names of all the individual db and log files prior to clicking OK. I now have 2 databases running independently.
0
 
LVL 7

Author Closing Comment

by:XGIS
ID: 39636736
Hello mikey, pls note I tried attach reattach also.  As soon as it goes live things get complex.   The rename at restore is the quickest and cleanest solution I could identify.  Thankyou for your input.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question