How to backup two databases and over write another

cmdolcet
cmdolcet used Ask the Experts™
on
I have my production Database that I would like to backup and then restore the data to a "sandbox" database. The problem is that I the production database is not the same name as the sandbox database.

How would I solve this issue and be able to backup the production data and rename it to the sandbox database.

Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Patrick BogersDatacenter platform engineer Lindows

Commented:
Hi

Just restore the sandbox db and in the process point to the backup files from the production one.

Cheers
SQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018
Commented:
>> How would I solve this issue and be able to backup the production data and rename it to the sandbox database.

There is nothing like a database restored from a backup should be in the same name..
So, simply go and restore with whatever name you want in your sandbox database server..
Hi,

but you need to make sure that you do not use the database name itself inside of any of the objects (SPs, UDFs, Views). So if there is something like "SELECT ... FROM ProductionDatabase.dbo.TableName" then of course you need to remove "Productiondatabase." from all these code lines as it is normally never needed to explicitly add the database name. This should be removed permanently, not only for the sandbox.

I recommend to use a tool like Redgate Search (free to download and install) which is able to search through all existing objects.

Cheers,

Christian

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial