1

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 ?

James_D
  • 201,275
  • 16
  • 291
  • 322
TomJ
  • 1,803
  • 14
  • 37
  • 57

2 Answers2

1

Easiest way:

DROP DATABASE project; CREATE DATABASE project;

longer way:

SHOW TABLES FROM project;

and iterate through the tables with

DROP TABLE project.<tablename>;
flaschenpost
  • 2,205
  • 1
  • 14
  • 29
  • Can I delete if the database is not empty ? – TomJ Apr 21 '14 at 15:47
  • Yeah, be careful with those commands. Normally the "working user" should not be allowed those commands, it should be task of a structure admin. – flaschenpost Apr 21 '14 at 15:48
  • What do you mean by that ? Can you explain it a little further ? – TomJ Apr 21 '14 at 15:49
  • 1
    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. – flaschenpost Apr 21 '14 at 16:07
-1

(this will clear the database)

 Truncate table tableName;