DROP statement is one of many powerful DDL commands. Be it
ALTER TABLE some_table DROP some_column or
DROP some_table, this type of command can drastically change your data landscape because in executing MySQL
DROP, you are completely removing objects from the database! If you are using the phpMyAdmin web interface, you can execute the MySQL
DROP statement with just a few mouse clicks. Continue reading to see how…
If you enjoy the content written here, by all means, share this blog and your favorite post(s) with others who may benefit from or like it as well. Since coffee is my favorite drink, you can even buy me one if you would like!
DROP statement is prevalent in most SQL dialects and is not limited in use to only MySQL.
Suppose we have a common ‘users’ table with 4 columns: ‘user_id’, ‘first_name’, ‘last_name’, and ‘country’:
For whatever reason, we have decided we no longer need the ‘country’ column and want to remove it completely from the ‘users’ table. How can we do that using MySQL
Removing a column with MySQL DROP statement in phpMyAdmin
In phpMyAdmin, simply check the checkbox on the far left on the column row you want to remove (in our example the ‘country’ column). Once chosen, click the Drop word just beside the red warning-like icon to complete the action. The screenshot below provides a complete visual overview of the steps.
!!!WARNING. YOU ARE ABOUT TO COMPLETELY REMOVE A COLUMN!!!
Not only am I myself extremely cautious, but so is phpMyAdmin. In carrying out the above-shown action, phpMyAdmin displays this warning message:
After clicking the OK button, the command is executed. The screenshot below shows, the ‘users’ table no longer has the ‘country’ column as part of its definition:
Removing a table with MySQL DROP statement in phpMyAdmin
Should you decide that you no longer need a table as part of your database, you can use the MySQL
DROP statement and completely remove it. Suppose I want to remove the ‘users’ table. How can I do that using the MySQL
First, check the checkbox on the far left for the table row you wish to remove. Then, click the Drop action word next to the warning-like icon. Essentially, the exact steps taken to remove a column, we are now applying them on a database level to the actual table object.
The below screenshot shows a visual overview of the entire process:
I’ll save my personal warning message in this section because phpMyAdmin provides one just the same:
Clicking the OK button executes the MySQL
DROP statement, removing the ‘users’ table from the database.
Recommended Reading and Informational Resources
Feel free to visit the below resources for more information on the MySQL
DROP statement, along with other blog posts I have written on using the phpMyAdmin web-based interface:
- DROP TABLE Statement
- ALTER TABLE Statement
- Data Definition Language
- Export MySQL data to CSV with phpMyAdmin
- Import CSV file data into MySQL table with phpMyAdmin
- MySQL CREATE TABLE in PHPMyAdmin – with examples.
Take good care when removing database objects like tables, columns, indexes, and the like using the MySQL
DROP statement. Always be sure that you actually want them completely removed from the database schema because once they are gone, they are indeed gone!
Like what you have read? See anything incorrect? Please comment below and thanks for reading!!!
A Call To Action!
Thank you for taking the time to read this post. I truly hope you discovered something interesting and enlightening. Please share your findings here, with someone else you know who would get the same value out of it as well.
Visit the Portfolio-Projects page to see blog post/technical writing I have completed for clients.
Be sure and visit the “Best Of” page for a collection of my best blog posts.
Josh Otwell has a passion to study and grow as a SQL Developer and blogger. Other favorite activities find him with his nose buried in a good book, article, or the Linux command line. Among those, he shares a love of tabletop RPG games, reading fantasy novels, and spending time with his wife and two daughters.
Disclaimer: The examples presented in this post are hypothetical ideas of how to achieve similar types of results. They are not the utmost best solution(s). The majority, if not all, of the examples provided, is performed on a personal development/learning workstation-environment and should not be considered production quality or ready. Your particular goals and needs may vary. Use those practices that best benefit your needs and goals. Opinions are my own.