/*
*功能:数据库备份
*dbname:数据库名称
*bakname:备份名称,包含完整路径
*/
use master
BACKUP DATABASE dbname TO disk='c:akName'
/*
*功能:数据库还原
*@dbname:数据库名称
*@bakname:备份名称,包含完整路径
*/
use master
declare @dbname nvarchar(500)
declare @bakname nvarchar(500)
set @dbname ='dbname'
set @bakname='c:akmame'
declare @spid nvarchar(20)
declare tb cursor for select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)
open tb
fetch next from tb into @spid
while @@fetch_status=0
begin
exec('kill '+@spid)
fetch next from tb into @spid
end close tb
deallocate tb
RESTORE DATABASE @dbname
FROM disk = @bakname
with replace