Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Detach Database

Author  Topic 

sunny_10
Yak Posting Veteran

72 Posts

Posted - 2013-05-01 : 07:49:26
Hi

I am running this query but it gives error "Cannot detach database , because it is currently in use"

EXEC sp_detach_db @dbname = "Test01"

Thanks

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-05-01 : 09:12:35
Run sp_who2 to see who is using the database. Also, if you are issuing the command while the current database is Test01, that can cause a problem as well. SO use
use master
GO
EXEC sp_detach_db @dbname = "Test01"
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2013-05-01 : 09:37:04
It will probably be safer just to set the DB offline.


ALTER DATABASE Test01 SET OFFLINE WITH ROLLBACK IMMEDIATE;

Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2013-05-01 : 14:17:19
quote:
Originally posted by Ifor

It will probably be safer just to set the DB offline.


ALTER DATABASE Test01 SET OFFLINE WITH ROLLBACK IMMEDIATE;





Depends on what the OP is trying to accomplish - although I do agree with your approach.
Go to Top of Page
   

- Advertisement -