完整备份和恢复

--backup
Use [DBName]
Declare @FullFileName Varchar(200)
Declare @FileFlag varchar(20)
Set @FileFlag='20'+convert(char(6),getdate(),12)
Set @FullFileName='d:\BackUp\'+@FileFlag+'.BAK'
BackUp DataBase [DBName] To Disk=@FullFileName with init

--restore
Declare @FullFileName Varchar(200)
Declare @FileFlag varchar(20)
Set @FileFlag='20'+convert(char(6),getdate(),12)
Set @FullFileName='d:\BackUp\'+@FileFlag+'.BAK'
RESTORE DATABASE [DBName] FROM DISK = @FullFileName
   WITH  MOVE 'DBName' TO 'd:\SQLData\DBName.mdf',
MOVE 'DBName_log' TO 'd:\SQLData\DBName_log.ldf'

 

posted @ 2017-05-31 10:41  芈璐  阅读(151)  评论(0编辑  收藏  举报