MySQL DROP TABLE Statement

MySQL DROP TABLE Statement

The DROP TABLE statement in MySQL is used to permanently delete an existing table from a database, along with all its data, indexes, and relationships.

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


🔹 Syntax



 

  • table_name → Name of the table to delete


🔹 Syntax with IF EXISTS



 

  • Prevents an error if the table does not exist


🔹 Example 1: Delete a Table



 

  • Deletes the table Students permanently.


🔹 Example 2: Delete Table If Exists



 

  • Deletes Students only if it exists; otherwise, no error occurs.


🔹 Deleting Multiple Tables



 

  • Deletes multiple tables at once


🔹 Key Points

  1. DROP TABLE deletes everything: data, indexes, triggers, and table structure.

  2. Always use IF EXISTS to avoid runtime errors.

  3. After dropping a table, it cannot be recovered unless you have a backup.

  4. Use SHOW TABLES; to check existing tables before dropping.


💡 Tip: Combine with SHOW TABLES; to verify tables 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 *