Gargi Narain
Gargi Narain

Reputation: 117

SQL Server database copy to another server (detach and attach)

I need to copy a database from one server to another. We follow the detach and attach method. However since replication is configured on the source server, every time we need to unconfigure the replication and detach the DB to copy. If I stop the SQL services and copy the .mdf and .ldf files, will it be same as detaching and copying?

Upvotes: 0

Views: 990

Answers (2)

SQLmojoe
SQLmojoe

Reputation: 2053

Don't use the attach/detach method; it keeps part of the replication configuration as you've already discovered. Besides, that will require taking your database offline, even if it's briefly.

Backup/restore of a DB configured for replication does not carry repl configuration with it. If all you need is a standalone copy of the DB, just do a backup using COPY_ONLY option and restore it wherever you need to. If you want to preserve the repl configuration, easiest way is to setup repl using scripts. That way, you just need to update the server/DB names whenever you need to deploy the same replication topology in a new environment. Strongly recommend you use variables for server & database names without actual values saved in the file. That way you only need to edit those each time you deploy and you won't accidentally deploy on the wrong server/database. See links to BOL below for additional details on each area:

Back Up and Restore Replicated Databases

Scripting Replication

Upvotes: 1

Greg
Greg

Reputation: 4055

There is no "correct" way to copy, because there are multiple ways to do so, and you do what works best for your scenario. in your case, if you simply need a copy of the db on another server, do a database backup/restore instead, as it will be simpler than attach/detach since replication is involved.

Upvotes: 0

Related Questions