We help IT Professionals succeed at work.

SQL Command to clone a database

craigdev
craigdev asked
on
171 Views
Last Modified: 2010-03-19
How would you copy a database using SQL commands?
Comment
Watch Question

Commented:
The easiest would be to use SSMS to generate the necessary scripts, copy them to the other computer, and then run them.

Select the database, right-click, Tasks > Generate scripts. Then walk through the wizard to make your choices.

You could write all of the scripts by hand, but it would take a while.

Commented:
Of course, another way to do it would be to create a backup and then restore it as a new database.

Author

Commented:
I want to do this from a .NET application which is why I need to figure out how to do it using SQL commands.
AneeshDatabase Consultant
CERTIFIED EXPERT
Top Expert 2009

Commented:
Do you mean to copy the data also ? In such case use BACKUP /RESTORE

Commented:
Are you trying to clone the entire database, certain tables, tables with data, or just the data?

Author

Commented:
The whole thing. I want to take a snapshot of the database at a moment in time. If my database was called DB_LIVE then a snapshot would be a functional database called DB_LIVE_20070822 which is an exact clone of the database as at today. Backup/restore would be fine but I need to send the instruction as a SQL command from the app.





Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.