Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Deleting all from all tables in MYSQL

by Anonymous Monk
on Sep 19, 2012 at 17:24 UTC ( [id://994485]=note: print w/replies, xml ) Need Help??


in reply to Deleting all from all tables in MYSQL

If you have referential integrity on your database it might slow things down a lot.   Consider dropping the database and re-creating it, perhaps by executing an external script which could be easily changed.   Perhaps you do not actually need Perl code to do this.
  • Comment on Re: Deleting all from all tables in MYSQL

Replies are listed 'Best First'.
Re^2: Deleting all from all tables in MYSQL
by justin423 (Scribe) on Sep 19, 2012 at 19:24 UTC
    it is a huge database and just for testing purposes, so speed isn't a concern, because everytime it runs, it still takes about 2 hours to run.

      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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://994485]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found