Create Duplicate SQL Database for Testing

前端 未结 7 1392
栀梦
栀梦 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:51

    First do a full backup your current database, which of course you have :)

    The you restore it to another one

    e.g. something like

    exec sp_addumpdevice 'Disk','LiveDataBackup',N'Insert backup file name here including path'
    Restore Database TestData From LiveDataBackup With File = 1,
    Move 'LiveData' To N'Path to where sqlserver expects the mdfs to be\TestData.mdf',
    Move 'LiveData_Log' To N'Path to where sqlserver expects the ldf to be\TaxData1.ldf',
    NORECOVERY,  NOUNLOAD,  STATS = 10
    RESTORE LOG [TestData] FROM  [LiveDataBackup] WITH  FILE = 2,  NOUNLOAD,  STATS = 10
    exec sp_dropdevice LiveDataBackup
    

    Above assume your live database is cunningly named LiveData and test, TestData.

    The path to where the mdf and ldf will be depends on the version of sql server and the instance name

    It should be something like C:\Program Files\Microsoft SQL Server\MSSQL11.DENALI\MSSQL\DATA\

    MSSQL11 because it's sql 2012, and DENALI is my instance name and it was installed by default in C: \Program Files

    Also there's no with replace, so if you wanted to run it again, you'd need to Drop your test database.

    There's probably some way to do this from the GUI, but I found it a massive PIA trying to relate the UI, to what I wanted to do.

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