I developed a project in JavaFX. Its back-end is MySQL. For my project I created a database named 'project' in MySQL. Now this database contains 8 tables. I want to make the database empty when a button is pressed, that is delete all tables, not database. Should I have to empty each table and delete them or is there any other easy way to clear the database ?
2 Answers
Easiest way:
DROP DATABASE project; CREATE DATABASE project;
longer way:
SHOW TABLES FROM project;
and iterate through the tables with
DROP TABLE project.<tablename>;
4 Comments
TomJ
Can I delete if the database is not empty ?
flaschenpost
Yeah, be careful with those commands. Normally the "working user" should not be allowed those commands, it should be task of a structure admin.
TomJ
What do you mean by that ? Can you explain it a little further ?
flaschenpost
You can define different users for the database (username/password for the MySQL-Connection), one can insert, delete, update and is used in the Web-App, the other user can also drop tables, drop databases, alter tables and so on. I just mean: be careful in which situations you fire a "DROP DATABASE" Command.