sql - Creating copy of database through stored procedure -


this question has answer here:

i have example database , in asp.net project need create copy of database name. i'm thinking of doing stored procedure.

is possible? if so, how?

the easiest way accomplish doing backup , restore of database:

backup database yourdatabasename disk = 'c:\yourbackupdir\backupfile.bak' copy_only; go 

and can restore accordingly:

restore database yournewdatabasename disk = 'c:\yourbackupdir\backupfile.bak'; go 

likewise, if on same server or if don't have similar directory structure database files live on, may need specify move clause:

restore database yournewdatabasename disk = 'c:\yourbackupdir\backupfile.bak'     move 'yourdatafilename' 'c:\newlocation\datafile1.mdf',     move 'yourlogfilename' 'c:\newlocation\logfile1.ldf'; go 

you can list of files running restore filelistonly disk = 'c:\yourbackupdir\backupfile.bak';.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -