MySQL DROP DATABASE Statement

MySQL DROP DATABASE Statement

The DROP DATABASE statement in MySQL is used to delete an existing database permanently along with all its tables, data, and objects.

⚠️ Warning: This action is irreversible. All data in the database will be lost.


🔹 Syntax


  • database_name → Name of the database to delete.


🔹 Syntax with IF EXISTS


  • Prevents an error if the database does not exist.


🔹 Example 1: Delete a Database


  • Deletes the database named SchoolDB permanently.


🔹 Example 2: Delete Database If Exists


  • Only deletes SchoolDB if it exists, otherwise no error occurs.


🔹 Key Points

  1. DROP DATABASE deletes everything: tables, views, procedures, triggers, and data.

  2. Always use IF EXISTS to avoid runtime errors.

  3. Use with caution; consider backups before dropping a database.

  4. After dropping, the database cannot be recovered unless you have a backup.


💡 Tip: Combine with SHOW DATABASES; to check existing databases before dropping:


 

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

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