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
You want to copy one Database_Production to Database_Testing in the same server. I would take database_production database as an example. I tested it in my server successfully.
Firstly, backup the database Database_Production.
backup database Database_Production to disk='H:\test\Database_Production.bark';
Secondly, restore Database_Production and this could rename the database name to Database_Testing.
restore database Database_Testing from disk='H:\test\Database_Production.bark' WITH move 'Database_Production_Data' to 'H:\test\Database_Testing_Data.mdf', move 'Database_Production_log' to 'H:\test\Database_Testing_Data.ldf'; GO
Then the database Database_Production is copied to database Database_Testing. The MOVE statement causes the data and log file to be restored to the specified locations. You do not need to create database Database_Testing and the script would create it.
using MS SQLServer 2012, you need to perform 3 basic steps
first, generate .sql file containing only the structure of the source DB
=> right click on the source DB and then Tasks then Generate Scripts => follow the wizard and u can save the .sql file locally
Second, replace in .sql file the source db with the destination one
=> right click on the destination file, open the .sql file and press New Query and Ctrl-H or (edit - find and replace - Quack replace)
finally, populate with data
=> right click on the detination DB, then Tasks and then Import Data => Data source drop dow set to ".net framework data procider for sql server" + set connection string text field under DATA ex: Data Source=Mehdi\SQLEXPRESS;Initial Catalog=db_test;User ID=sa;Password=sqlrpwrd15
=> Same thing to do with the destination => check the table you want to transfer or check box besides "source :....." to check all of them
you are done.
If you need to create a database on the same server just create the empty database. Right Click on it and Select Restore-> Choose the database you want to make a copy of and click okay.
use copy database option in SQL server management studio
You can follow (this)
I found this method to be most effective on SQL Server 2005 and 2008, Express Editions:
From the Microsoft Docs:
SSMS will restore your .bak file to a new database, according to the name that you give it.