Home  >  Article  >  Database  >  数据库备份遇到的问题

数据库备份遇到的问题

WBOY
WBOYOriginal
2016-06-07 16:12:101232browse

1、没有数据库时先创建一个同名数据库,然后选择备份,此时需要全备份,分量备份不可以 如果都正常操作还提示备份集中的数据库备份与现有不同则用语句执行 RESTORE DATABASE workpointmanage_sassFROM DISK = C:\Program Files\Microsoft SQL Server\MSSQL10

1、没有数据库时先创建一个同名数据库,然后选择备份,此时需要全备份,分量备份不可以

如果都正常操作还提示“备份集中的数据库备份与现有不同”则用语句执行

 

RESTORE DATABASE workpointmanage_sass
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\workpointmanage_sass_datafull_201412040742_12040742.bak'   --bak文件路径
with replace,
MOVE 'workpointmanage_sass' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\workpointmanage_sass.mdf',   --mdf文件路径
MOVE 'workpointmanage_sass_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\workpointmanage_sass.ldf'   --ldf文件路径

 

2、数据库还原中提示数据库正在被占用,需要分离数据库再联机,手动操作无效时可用如下语句

declare @dbname varchar(20)

set @dbname='workpointmanage_sass'

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(&#39;kill &#39;+@spid)--终止正常连接

fetch next from getspid into @spid

end

close getspid

deallocate getspid

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn