Posted on Leave a comment

Restoring a SQL server database

I was trying to move a database from the client’s existing live site to our testing database on another server.

(I actually have three databases atm, one is the existing db used for the site (old server), the second is one that I used to test before I initially put the site live (new server), and the third is one that is for the new site about to replace the current one (new server))

After much frustration, this is how I managed to move the database over and then transfer the information I needed:

1. Create the new db (or skip this step if you are going to restore to a testing database).
2. Backup the current db from the old server and transfer to the new server
3. Through EM on the new server right click the created db>All Tasks>restore database
4. Browse to the backup of the db by selecting a new device
5. Under options choose restore over existing db and be sure to have the path and names of the mdf and ldf match what is on your server for your other databases. It will be listed with the path and names from the old server.
6. You may receive an error saying it can not import over existing files. If so then specify a directory under your current data and log directories (such as one named imported).
7. Be sure to remove the old users from the other db and add the user your cp created for the db. If objects are owned by a user on the old server you will need to change ownership over to dbo before removing the old user. If this is needed there are queries through google that will change the ownership of tables and sps through query analyizer.

How to change the database owner:
Exec sp_changeobjectowner ‘dbo12323.my_table’,’dbo’

dbo12323 = make this whatever the table currently has as the db owner
dbo = the new db owner

Now I can go ahead and move the information over to my new database.
INSERT INTO myDatabase.dbo.tbl_myTable
(field1, field2, field3)
SELECT
source1, source2, source3
FROM oldDatabase.dbo.tbl_oldTable

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.