首页 >数据库 >mysql教程 >数据库备份操作

数据库备份操作

WBOY
WBOY原创
2016-06-07 14:59:471082浏览

--备份 BACKUP DATABASE [JD_Business] TO DISK = N'E:\数据库备份\testbackupNEW.bak' WITH NOFORMAT, NOINIT, NAME = N'testbackup-完整数据库备份', SKIP, NOREWIND, NOUNLOAD, STATS = 10 GO --终止进程语句方法 use master declare @dbname varchar(20)

--备份
BACKUP DATABASE [JD_Business] TO DISK = N'E:\数据库备份\testbackupNEW.bak' WITH NOFORMAT, NOINIT, NAME = N'testbackup-完整数据库备份', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO

 


--终止进程语句方法
use master
declare @dbname varchar(20)
set @dbname='JD_Business' ---这是数据库名称
declare @sql nvarchar(500)
declare @spid int--SPID 值是当用户进行连接时指派给该连接的一个唯一的整数
set @sql='declare getspid cursor for
select spid from sysprocesses where dbid=db_id('''+@dbname+''')'
exec (@sql)
open getspid
fetch next from getspid into @spid
while @@fetch_status-1--如果FETCH 语句没有执行失败或此行不在结果集中。
begin
exec('kill '+@spid)--终止正常连接
fetch next from getspid into @spid
end
close getspid
deallocate getspid


--终止进程语句方法
declare @d varchar(8000)
set @d=''
select @d=@d+' kill '+cast(spid as varchar)+char(13)
from master..sysprocesses where dbid=db_id('JD_Business')
exec(@d)

 

 


--还原
RESTORE DATABASE [JD_Business] FROM DISK = N'E:\数据库备份\testbackupNEW.bak' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10
GO

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn