首页 > 代码库 > 完整备份和恢复

完整备份和恢复

--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

 

完整备份和恢复