Solved

How to rename MSSQL DB Permanently After Restore?

Posted on 2013-11-05
5
305 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
  • 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

828 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