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!

Tags: , , ,

No comments yet.

Leave a Reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.