日期:2014-05-18 浏览次数:20730 次
--原因其他用户或进程在用着数据库 /* 关闭用户打开的进程处理 */ use master go if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[p_killspid] go create proc p_killspid @dbname varchar(200) --要关闭进程的数据库名 as declare @sql nvarchar(500) 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 go --关闭对数据库account 的连接 exec p_killspid 'account' go --结束后删除存储过程 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[p_killspid] go --更改排序规则 --数据库中区分大小写 alter database test COLLATE Chinese_PRC_CS_AS --恢复默认的不区分大小写 alter database test COLLATE Chinese_PRC_CI_AS
------解决方案--------------------
RESTORE DATABASE 表名 FROM DISK = '设备路径' with replace,recovery,
move '逻辑名称 ' to '路径',
move '逻辑名称_log ' to '路径.ldf '
------解决方案--------------------
先把数据库设成单用户再还原