postgresql
  1. postgresql-drop-db

DROP DATABASE - (PostgreSQL Database)

The DROP DATABASE statement is a PostgreSQL command that is used to remove a database. In this tutorial, we will discuss the syntax, example, output, explanation, use, important points, and summary of DROP DATABASE statement.

Syntax

DROP DATABASE [IF EXISTS] database_name;
  • IF EXISTS (optional): Use this clause to avoid an error if the database does not exist.
  • database_name: The name of the database to drop.

Example

Let's take a look at an example of using the DROP DATABASE statement in PostgreSQL.

DROP DATABASE mydatabase;

In this example, the DROP DATABASE statement is used to drop the database named 'mydatabase'.

Output

If the DROP DATABASE command is successful, PostgreSQL will return a message indicating that the database has been dropped.

DROP DATABASE

Explanation

The DROP DATABASE statement is used to remove a database permanently. Once a database is dropped, all of its data and objects are permanently deleted. The IF EXISTS clause can be used to avoid an error if the database does not exist.

Use

The DROP DATABASE statement is used to remove a database when it is no longer needed or when you want to start fresh with a new database.

Important Points

  • The DROP DATABASE statement permanently deletes a database and all of its data and objects.
  • The user executing the DROP DATABASE command must have DROP privileges on the target database.
  • Be careful when using the DROP DATABASE statement because it can not be undone.
  • Always use the IF EXISTS clause to avoid an error if the database does not exist.

Summary

In this tutorial, we discussed the DROP DATABASE statement in PostgreSQL. We covered the syntax, example, output, explanation, use, and important points of the DROP DATABASE statement. With this knowledge, you can now use the DROP DATABASE statement to remove a database permanently from your PostgreSQL server.

Published on: