Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Deleting all from all tables in MYSQL

by Tux (Abbot)
on Sep 20, 2012 at 06:55 UTC ( #994591=note: print w/replies, xml ) Need Help??


in reply to Re^2: Deleting all from all tables in MYSQL
in thread Deleting all from all tables in MYSQL

In that case, dropping the database and recreating it is most likely the fastest solution. Database drops in PostgreSQL and MySQL/MariaDB are almost instant. In Oracle it takes ages to (re)create a database.

To get all tables, why not use the DBI::tables? That way you don't have to dig into database specific calls.

If you still want to delete in stead of re-create, why use a prepare/execute combo instead of just do?

    $dbh->do ("truncate table $_") for $dbh->tables (undef, undef, undef, "TABLE");

or

    $dbh->do ("delete   from  $_") for $dbh->tables (undef, undef, undef, "TABLE");

In other databases, you could use delete from table cascade, but iirc that syntax is not supported by mysql where you'd have to create the table to know about cascading deletes.


Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994591]
help
Chatterbox?
[TCLion]: Good Morning Monks, I am parsing logs and some date time formats are inconsistent. I am trying to make output all same format. What is the best way to convert a month(word) to month(number)?
[Corion]: TCLion: I'm not aware of a better way than manually building the hash, as all strptime incarnations I know have nasty edge cases
[davido]: And remember; time is hard. :) As soon as you think, I've got this, you'll discover that time is harder than that. :)
[1nickt]: TCLion are you parsing the dates with DateTime or another tool?

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2017-03-23 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (287 votes). Check out past polls.