View Full Version : Empting a database
draco_iii
07-21-2003, 05:05 PM
How can I empty a database of all information?
Spookster
07-21-2003, 05:33 PM
Well the easiest way of course is just to drop the database:
http://www.mysql.com/doc/en/DROP_DATABASE.html
and then recreate it:
http://www.mysql.com/doc/en/CREATE_DATABASE.html
Or if you wish to just drop the tables within the database then:
http://www.mysql.com/doc/en/DROP_TABLE.html
How can I empty a database of all information?
Depends on what you need. If you just need the tables ampty, but you need the autonum values to keep going up as if no records were deleted, then you can just delete alle records by using a loop in PHP or another scriptig language. Like
$result = mysql_list_tables($database, $conn);
if ($result) {
for($i=0; $i <mysql_num_rows($result); $i++) {
$query_del="delete from " . mysql_tablename($result, $i) ;
$del = mysql_query($query_del, $conn);
if ($del) {
echo "All records from table " . mysql_tablename($result, $i) . " deleted";
}
else {
echo "Problem when deleting records from table" . mysql_tablename($result, $i)
}
}
}
else {
echo " Databaseproblem. No records deleted from this databases tables"
}
Not tested. Best try it out on a copy of your db
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.