SQL 102 — DROP DATABASE

While deleting a database is a fairly rare occurrence, I’m teaching you now, since it’s a pretty easy task to learn. Before teaching you this, you do know rule number 2, right?
I bring this up because, you never know when you’ll get a request to drop a database, only to get a call 5 seconds after you’ve done it saying, “I just remembered, I need something out of that database!” If you follow rule number 2, Have a tested Backup and Recovery Plan, you’ll never have to look for a new job because of a user’s mistake.

Now, on to the lesson.

To delete a database, you use the DROP DATABASE command followed by the name of the database. The formula used is:

DROP DATABASE DatabaseName;

Here is an example:

DROP DATABASE JabbaPalaceInventory;

Hopefully, you’re not running this until after his barge explodes, and his palace has been completely looted, or you’re doing the looting yourself 🙂

Again, since you know the rules, Rule number 4 still applies, so I’ll include my standard DROP DATABASE template.

/* ----------------------------------------------------------------------------
-- DROP DATABASE template
-- yyyymmdd sdl: initial commit
-- yyyymmdd sdl: change x
---------------------------------------------------------------------------- */
USE master
GO
-- Make sure your database still exists
IF  EXISTS (
  SELECT
	name
  FROM sys.databases
  WHERE
    name = N''
)
BEGIN
  DROP DATABASE
GO

If you want to DROP your database visually, please refer to the msdn for those instructions.

If you have any questions, please let me know. I’m here to help!

By Shannon Lowder

Shannon Lowder is the Database Engineer you've been looking for! Look no further for expertise in: Business Analysis to gather the business requirements for the database; Database Architecting to design the logical design of the database; Database Development to actually build the objects needed by the business logic; finally, Database Administration to keep the database running in top form, and making sure there is a disaster recovery plan.

Leave a comment

Your email address will not be published. Required fields are marked *