Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL 2005 - quick way to quickly duplicate a database + data

I have my development database, I want to spin off a duplicate for testing. I want to do this often.

What's the fastest and easiest way to do this often? I can get the job done by generating scripts w/ data included but I feel like there must be a better way. Should I back up database 1 then screw around with it so I can restore it as a different name?

like image 492
dfasdljkhfaskldjhfasklhf Avatar asked Jan 14 '09 15:01

dfasdljkhfaskldjhfasklhf


1 Answers

Detach the database, copy the .MDF file (and .ldf file) and you can attach both. Or only one, to keep one as a copy for a fast copy later.

The "Copy database" command from Mcirosoft SQL Server Management Studio can also work like this.

You can automate/script this easily, using PowerShell or just .Cmd files with calls to osql.

like image 186
GvS Avatar answered Oct 01 '22 05:10

GvS