I would like to delete all the tables from database, but not deleting the database itself. Is it possible ? I'm just looking for shorter way than removing the database and create it again. Thanks !
Connect to the target database. Select all tables from the left sidebar. Right-click and choose delete, or simply hit delete button. Press Cmd + S to commit changes to the server.
Removing a Table from Database. You can use the DROP TABLE statement to easily delete the database tables that you no longer need. The DROP TABLE statement permanently erase all data from the table, as well as the metadata that defines the table in the data dictionary.
You can select all the available tables from the right sidebar, right click and choose Delete.. , or press Delete key to drop all.
The shortest is to re-create database. but if you don't want to...
This is for MySQL/PHP. Not tested but something like that.
$mysqli = new mysqli("host", "my_user", "my_password", "database"); $mysqli->query('SET foreign_key_checks = 0'); if ($result = $mysqli->query("SHOW TABLES")) { while($row = $result->fetch_array(MYSQLI_NUM)) { $mysqli->query('DROP TABLE IF EXISTS '.$row[0]); } } $mysqli->query('SET foreign_key_checks = 1'); $mysqli->close();
There is no simple way to do this. Either you'll need to know what the tables are in advance:
//edit you can get this information using the query SHOW TABLE STATUS
$tables = array('users','otherdata'); foreach($tables as $table){ db.execute("DROP TABLE "+$table); }
or you can drop the database and re-create it empty (it's really not that much effort!):
db.execute('DROP DATABASE SITEDATA'); db.execute('CREATE DATABASE SITEDATA');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With