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 ?

2
  • stackoverflow.com/questions/3476765/… Commented Apr 21, 2014 at 15:45
  • Again, this has nothing to do with javafx. Please use the proper tags. Commented Apr 21, 2014 at 17:08

2 Answers 2

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>;
Sign up to request clarification or add additional context in comments.

4 Comments

Can I delete if the database is not empty ?
Yeah, be careful with those commands. Normally the "working user" should not be allowed those commands, it should be task of a structure admin.
What do you mean by that ? Can you explain it a little further ?
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.
-1

(this will clear the database)

 Truncate table tableName; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.