9

How can I restore a live database without taking its backup first?

We can do this from SQL Server Management Studio, but I want to do this with script, which i can run as a scheduled job.

2 Answers 2

6

Choose restore source - another DB. To generate a SQL script - press the button

https://i.sstatic.net/q6RLm.png

Sign up to request clarification or add additional context in comments.

1 Comment

Major pitfall: this only restores from the last backup. If the last backup is rather old, you would end up with old data. (For everyone that isn't reading the other answer)
4

Please Note: Using of SQL Server Management Studio for restoring database with "From database" option, however, restores database from existed backup.

Maybe you need to copy database. In this case you should to use backup/restore combination like:

The following example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks2008R2 database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB.

Copy
BACKUP DATABASE AdventureWorks2008R2 
   TO AdventureWorks2008R2Backups ;

RESTORE FILELISTONLY 
   FROM AdventureWorks2008R2Backups ;

RESTORE DATABASE TestDB 
   FROM AdventureWorks2008R2Backups 
   WITH MOVE 'AdventureWorks2008R2_Data' TO 'C:\MySQLServer\testdb.mdf',
   MOVE 'AdventureWorks2008R2_Log' TO 'C:\MySQLServer\testdb.ldf';
GO

Here the example how to automate the process of databse copying - Create a copy of an existing SQL Server database

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.