SQLServer:SQL备份语句SQLServer:SQL备份语句
2009-06-25 14:07
--完整备份
  Backup Database NorthwindCS
  To disk=’G:\Backup\NorthwindCS_Full_20070908.bak’
  --差异备份
  Backup Database NorthwindCS
  To disk=’G:\Backup\NorthwindCS_Diff_20070908.bak’
  With Differential
  --⽇志备份,默认截断⽇志
  Backup Log NorthwindCS
  To disk=’G:\Backup\NorthwindCS_Log_20070908.bak’
  --⽇志备份,不截断⽇志
  Backup Log NorthwindCS
  To disk=’G:\Backup\NorthwindCS_Log_20070908.bak’
  With No_Truncate
  --截断⽇志不保留
  Backup Log NorthwindCS
  With No_Log
  --或者
  Backup Log NorthwindCS
  With Truncate_Only
  --截断之后⽇志⽂件不会变⼩
  --有必要可以进⾏收缩
  --⽂件备份
  Exec Sp_Helpdb NorthwindCS --查看数据⽂件
  Backup Database NorthwindCS
  File=’NorthwindCS’ --数据⽂件的逻辑名
  To disk=’G:\Backup\NorthwindCS_File_20070908.bak’
  --⽂件组备份
  Exec Sp_Helpdb NorthwindCS --查看数据⽂件
  Backup Database NorthwindCS
  FileGroup=’Primary’ --数据⽂件的逻辑名
  To disk=’G:\Backup\NorthwindCS_FileGroup_20070908.bak’
  With init
  --分割备份到多个⽬标
  --恢复的时候不允许丢失任何⼀个⽬标
  Backup Database NorthwindCS
  To disk=’G:\Backup\NorthwindCS_Full_1.bak’
  ,disk=’G:\Backup\NorthwindCS_Full_2.bak’
  --镜像备份
  --每个⽬标都是相同的
  Backup Database NorthwindCS
  To disk=’G:\Backup\NorthwindCS_Mirror_1.bak’
  Mirror
  To disk=’G:\Backup\NorthwindCS_Mirror_2.bak’
  With Format --第⼀次做镜像备份的时候格式化⽬标
  --镜像备份到本地和远程
  Backup Database NorthwindCS
  To disk=’G:\Backup\NorthwindCS_Mirror_1.bak’
  Mirror
  To disk=’\\192.168.1.200\Backup\NorthwindCS_Mirror_2.bak’
  With Format
  --每天⽣成⼀个备份⽂件
  Declare @Path Nvarchar(2000)
  Set @Path =’G:\Backup\NorthwindCS_Full_’
  +Convert(Nvarchar,Getdate(),112)+’.bak’
  Backup Database NorthwindCS
  To www.hack58/Article/html/3/7/2008/mailtdisk=@Path
  --从NoRecovery或者
  --Standby模式恢复数据库为可⽤
  Restore Database NorthwindCS_Bak
  With Recovery
  --查看⽬标备份中的备份集
  Restore HeaderOnly
  Restore HeaderOnly
  From Disk =’G:\Backup\NorthwindCS_Full_20070908.bak’
  --查看⽬标备份的第⼀个备份集的信息
  Restore FileListOnly
  From Disk =’G:\Backup\NorthwindCS_Full_20070908_2.bak’
  With File=1
  --查看⽬标备份的卷标
  Restore LabelOnly
  From Disk =’G:\Backup\NorthwindCS_Full_20070908_2.bak’
  --备份设置密码保护备份
  Backup Database NorthwindCS
sqlserver备份表语句  To disk=’G:\Backup\NorthwindCS_Full_20070908.bak’
  With Password = ’123’,init
  Restore Database NorthwindCS
  From disk=’G:\Backup\NorthwindCS_Full_20070908.bak’
  With Password = ’123’
备份:backup database dbname to disk=';d:\dbn.aa';
恢复:restore database dbname from disk=';d:\dbn.aa';
恢复必须在单⽤户模式下操作才能够成功,我们需要断开其他⽤户的连接,并且切换到其他数据库,才能够成功

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。