use master
go
detach the database 'database0'

解决方案 »

  1.   

    回复烛光:我用的是,exec sp_detach_db 'database0';和你的用法有什末区别吗
      

  2.   

    你可以隔几分种后执行上述代码就可以了。
    或者用大力的杀进程存储过程,如下:
    /***************************
        杀进程存储过程
    ***************************/
    use master
    go
    if exists(select name from dbo.sysobjects where id=object_id(N'dbo.p_killspid') and objectproperty(id,N'IsProcedure')=1)
    drop proc p_killspid
    go
    create  proc p_killspid  (@dbname  varchar(20))  
    as  
    begin  
    declare  @sql  nvarchar(500)  
    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  
    declare @a varchar(100)
    while  @@fetch_status  <  >-1  
    begin 
    set @a='kill  '+rtrim(@spid) 
    exec(@a)  
    fetch  next  from  getspid  into  @spid  
    end  
    close  getspid  
    deallocate  getspid  
    end  
    GO-- 调用
    use master
    go
    exec p_killspid 'pubs'
      

  3.   

    终于搞定,原来要sleep一段时间