sql - Creating copy of database through stored procedure -
this question has answer here:
- sql server: backup databases 2 answers
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
Post a Comment