Link to home
Start Free TrialLog in
Avatar of craigdev
craigdev

asked on

SQL Command to clone a database

How would you copy a database using SQL commands?
Avatar of ptjcb
ptjcb
Flag of United States of America image

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.
Of course, another way to do it would be to create a backup and then restore it as a new database.
Avatar of craigdev
craigdev

ASKER

I want to do this from a .NET application which is why I need to figure out how to do it using SQL commands.
Avatar of Aneesh
Do you mean to copy the data also ? In such case use BACKUP /RESTORE
Are you trying to clone the entire database, certain tables, tables with data, or just the data?
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.





ASKER CERTIFIED SOLUTION
Avatar of ptjcb
ptjcb
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial