I have created a database on SQL server and a front end user application in winforms c#. It's up and running and working fine, but I've now been asked to set up a test version by the client for training new employees, so they can put in dummy data whilst they are trained without effecting the 'real' live database.
When I installed the database I had it all scripted, but things have changed since, and I don't particularly want to script all the tables again.
Is there a fast, convenient way of duplicating the database (and its data) on the same server, but under a different name?
EDIT (subsequent to Tony Hopkinson post)
I've got as far as this
exec sp_addumpdevice 'Disk','MyDatabaseBackup',N'D:\MyDatabaseBackup' Restore Database MyDatabase From MyDatabaseBackup With File = 1, Move 'MyDatabase' To N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLE\MSSQL\DATA\MyDatabaseTEST.mdf', Move 'MyDatabase_Log' To N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLE\MSSQL\DATA\MyDatabaseTEST_log.ldf', NORECOVERY, NOUNLOAD, STATS = 10 RESTORE LOG [MyDatabaseTEST] FROM [MyDatabaseBackup] WITH FILE = 2, NOUNLOAD, STATS = 10 exec sp_dropdevice MyDatabaseBackup
But I'm getting the following error message
Msg 3234, Level 16, State 2, Line 2 Logical file 'MyDatabase' is not part of database 'MyDatabase'. Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Line 2 RESTORE DATABASE is terminating abnormally. Msg 3154, Level 16, State 4, Line 6 The backup set holds a backup of a database other than the existing 'MyDatabaseTEST' database. Msg 3013, Level 16, State 1, Line 6 RESTORE LOG is terminating abnormally. Device dropped.
use copy database option in SQL server management studio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With