use masterexec sp_dboption 'portal', 'dbo use only', 'true'declare @spid int declare @esql varchar(32) declare spidcur cursor for select spid from sysprocesses where dbid = db_id('portal') open spidcur while 1=1 begin FETCH NEXT FROM spidcur INTO @spid if @@FETCH_STATUS <> 0 break
select @esql = 'KILL ' + Cast(@spid as char) EXEC ( @esql ) end close spidcur deallocate spidcur
use master go create proc killspid (@dbname varchar(20)) as begin declare @sql nvarchar(500),@temp varchar(1000) declare @spid int 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 begin set @temp='kill '+rtrim(@spid) exec(@temp) fetch next from getspid into @spid end close getspid deallocate getspid end --用法 use master exec killspid '数据库名'
gorestore database portal from disk='portal' with norecovery
go
use master
restore database portal from disk='portal' with norecovery这样还是出现刚才的错误提示!
restore database portal from disk='portal'
加的这个数据库,数据库文件是从别的机器里备过来的
但是我想服务器上的这个数据库更新了,所以我备了一个,就想
restore database portal from disk='portal' with norecovery
这样追加,怎么就不行呢?
我把这个断掉也不行。因为数据库正在使用,所以未能获得对数据库的排它访问权。
---->如何设置数据库的访问权限,也就是可以多人访问?
declare @esql varchar(32)
declare spidcur cursor for
select spid from sysprocesses where dbid = db_id('portal')
open spidcur
while 1=1
begin
FETCH NEXT FROM spidcur INTO @spid
if @@FETCH_STATUS <> 0 break
select @esql = 'KILL ' + Cast(@spid as char)
EXEC ( @esql )
end
close spidcur
deallocate spidcur
go
create proc killspid (@dbname varchar(20))
as
begin
declare @sql nvarchar(500),@temp varchar(1000)
declare @spid int
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
begin
set @temp='kill '+rtrim(@spid)
exec(@temp)
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end --用法
use master
exec killspid '数据库名'
如果还不行,你去“当前进程”看一下是否有人用当前数据库,
如果有,就kill掉他。