0

i need sql script for copy database with data in sql server 2008 r2.I tried the below script but not working in sql server 2008.

DBCC CLONEDATABASE ('MyDatabase', 'MyDatabase_Copy')
1
  • you cannot do a backup and restore? Commented Nov 4, 2017 at 9:11

1 Answer 1

2

If you want to make a copy of the full database to another one you can make a full backup of the existing one and restore it as another database.

To perform a backup you can do doing something like this:

BACKUP DATABASE MyDatabase TO DISK='C:\Backup directory\MyDatabase.bak'
  WITH INIT, FORMAT, SKIP

Then you restore that backup in the destination database (either overwriting an existing database or creating a new one):

RESTORE DATABASE MyDatabase_Copy FROM DISK='C:\Backup directory\MyDatabase.bak'
  WITH REPLACE

If the destination database already exists you could need to use the MOVE option in the restore step (or perform a DROP DATABASE MyDatabase_Copy before restoring).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.