Create Duplicate SQL Database for Testing

前端 未结 7 1385
栀梦
栀梦 2021-02-01 03:07

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

相关标签:
7条回答
  • 2021-02-01 03:32

    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.

    0 讨论(0)
  • 2021-02-01 03:33

    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.

    0 讨论(0)
  • 2021-02-01 03:35

    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.

    0 讨论(0)
  • 2021-02-01 03:40

    use copy database option in SQL server management studio

    enter image description here

    0 讨论(0)
  • 2021-02-01 03:40
    • Dump your database into a backup file
    • Re-create your database from your dump - that is a script which you can run - with different name (that you have to change into the script)

    You can follow (this)

    0 讨论(0)
  • 2021-02-01 03:48

    I found this method to be most effective on SQL Server 2005 and 2008, Express Editions:

    From the Microsoft Docs:

    1. Right click on the database you want to duplicate and choose Tasks->"Back Up..."
    2. Save the back up to a .bak file
    3. Right click on the "Databases" folder in the Object Explorer in SQL Server Management Studio
    4. Choose "Restore Database"
    5. As the source, select "File" and point to the .bak file you created earlier.
    6. Change the name of the database to restore to (this was the key step for me - you are not constrained to the options in the dropdown.)

    SSMS will restore your .bak file to a new database, according to the name that you give it.

    0 讨论(0)
提交回复
热议问题