天津网站设计教您如何备份和还原数据库
更新时间:2012/10/25 点击:1516次
use master
backup database [oems] to disk = 'F:/1.bak' with name = 'oems'
declare @spid int
declare @sql nvarchar(500)
declare cur_rows cursor local for
select spid from sysprocesses where dbid=db_id('oems')
open cur_rows
fetch cur_rows into @spid
while @@fetch_status=0
begin
set @sql = 'kill ' + cast( @spid as nvarchar( 500 ))
exec(@sql)
fetch cur_rows into @spid
end
close cur_rows
restore Database [oems] from disk = 'F:/1.bak' with file = 1 , recovery
还原之后在执行与数据库的操作时会出现常规网络错误,第二次就没有了.暂时的解决办法是用读一次的方式.