I have a database in SQL Server 2008 that I am trying, unsuccessfully, to delete. I open management studio, right click on the database, choose delete from the menu, and one of two things happens. One, SQL Server tells me that the database can't be deleted because it is in use or two, it "acts" as if it is going to work -- the "executing" wheel just spins and spins but nothing happens.
I've tried to use the following without success:
USE Master;
GO
DROP DATABASE dbname;
GO
I get the same results with that as with using the Delete pick from the menu.
I've also tried the following but it just tells me that the query is executing and it never stops
ALTER DATABASE MyDatabaseName
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE
When I stop that query from executing, there are a bunch of lines in the output window which tell me "Nonqualified transactions are being rolled back. Estimated rollback completion: 100%".
I have stopped SQL Server and restarted it and I've stopped everything else that I can think could possibly connect to it. Any ideas?
I find that odd to say the least and I suspect was just a coincidence. If you have permission to drop a database you can do it, otherwise you are out of luck. I suspect what was happening was that you were trying to drop the database while you were still in the same database. By changing to sa all you did was connect to a different database be default (probably master). In future, if you want to drop a database do it this way:
USE master
ALTER DATABASE [YourDatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE [YourDatabaseName]
Since I solved the problem, what do I do about awarding points on this one?
Select your comment as the solution