Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm almost done testing my DB with junk text and am ready to wipe out all the rows in the row to start over.
my $data = qq(DELTE * FROM tablename); my $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr;
This code errors out saying I have an error in the MYSQL statement and I can't figure it out.

Replies are listed 'Best First'.
Re: Easy way to clear a mysql table?
by RichardK (Parson) on Sep 08, 2011 at 14:23 UTC
     TRUNCATE TABLE tablename

    will also free up any used space & can be faster if you're removing lots of data.

Re: Easy way to clear a mysql table?
by mje (Curate) on Sep 08, 2011 at 14:06 UTC

    I think you'll find the operation is DELETE (you spelt it incorrectly) and it is "delete from table", no "*".

Re: Easy way to clear a mysql table?
by erix (Prior) on Sep 08, 2011 at 14:00 UTC
    > my $data = qq(DELTE * FROM tablename);

    tpyo: it says DELTE instead of DELETE...

    (And maybe TRUNCATE is useful for your case...)

Re: Easy way to clear a mysql table?
by blue_cowdawg (Monsignor) on Sep 08, 2011 at 14:31 UTC

    $dbh->do(qq(delete from tablename where 1=1 ));

    You forgot to mention what errors you saw when you tried your code...

    Also do you have permissions to drop from the table? Silly question I realize, but worthy of asking none-the-less.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Easy way to clear a mysql table?
by Corion (Patriarch) on Sep 08, 2011 at 13:59 UTC

    What part of your question relates to Perl? Have you tried running your SQL statement outside of Perl?

    What steps have you taken to ensure that your statement is correct?