开发者

duplicating database

开发者 https://www.devze.com 2023-01-07 11:19 出处:网络
how to duplicate wh开发者_如何学Cole database in sqlThe easiest way is to take a COPY_ONLY backup then restore it (optionally under a different name)Agree - backup and restore (under a different name

how to duplicate wh开发者_如何学Cole database in sql


The easiest way is to take a COPY_ONLY backup then restore it (optionally under a different name)


Agree - backup and restore (under a different name if on the same server / instance).

If you need to keep them totally in synch after restoration, look at mirroring or log shipping (depending on what you need to do with the DB copy). Partial or conditional synchronisation can be done using replication.


The backup is the simplest, and the first thing that comes to mind.

Alternatively you can use the Schema and Data compare tools from RedGate. Or even the packager, depending on your need.

Run them comparing your current database to an empty database. They'll generate lovely scripts, and it's repeatable for differential copies in future.

We use them here, they're great.


You can do with the following options:


  1. If you want to copy the database to another server with the same name, take full backup and restore this backup.
  2. Script the entire database and execute this script in new database. Now use SQL Server import/export wizard to import the data to new database. Please ensure that you have executed the script before you import, otherwise relationships and keys will be ignored.
  3. You can restore one database backup to another database through SQL Script: Here is the script:

RESTORE DATABASE [yourExistingDB] FROM DISK = 'C:\Backup\yourFullBackup.bak' WITH FILE = 1, MOVE 'newDB' TO 'C:\newDB.mdf', MOVE 'newDB_log' TO 'C:\newDB_log.ldf', NOUNLOAD, REPLACE, STATS = 10

GO

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号