1

I am trying to drop a user-defined database, like so:

create database demo;
drop database demo;

But I get the error

Cannot drop the database 'demo', because it does not exist or you do not have permission.

1
  • 2
    There is nothing wrong with your code so my guess would be that you don't have permissions to delete the database. Commented Jun 1, 2011 at 11:25

2 Answers 2

1

One way to sort this out might be to run

SELECT name FROM sys.databases

to see if the database does exist.

Some helpful tips from MSDN:

  • To use DROP DATABASE, the database context of the connection cannot be the same as the database to be dropped. You could change your context to, for example USE master before running DROP
  • To execute DROP DATABASE, at a minimum, a user must have CONTROL permission on the database.

You might find some other useful information there that applies to your specific situation.

Sign up to request clarification or add additional context in comments.

Comments

0
create database demo;
drop database demo;

In the above code, if the database is deleted and again tried to delete the database which does not exists will give you the error as you mentioned

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.