how to drop user defined database in sql server 2005?
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', 开发者_如何学Pythonbecause it does not exist or you do not have permission.
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 exampleUSE master
before runningDROP
- To execute
DROP DATABASE
, at a minimum, a user must haveCONTROL
permission on the database.
You might find some other useful information there that applies to your specific situation.
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
精彩评论