How to delete each data of each table?

Discussion in 'MySQL' started by Adulu, Aug 22, 2007.

  1. #1
    I have 190 table of one datebase, I would like to delete one data on each table.
    therefore,i use phpmyadmin tools but it only support delete data one by one
    [​IMG]

    I would like to delete each data of each table at a time.

    someone could help me?
    thank you
     
    Adulu, Aug 22, 2007 IP
  2. Coder

    Coder Banned

    Messages:
    311
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use Query Analyzer and run multiple queries at a time...
    This May help you
     
    Coder, Aug 23, 2007 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    What are the table names, fieldname of table which has this data, and data you want to match?
    Can give you queries if you can give this info.
    Bye :)
     
    JEET, Aug 23, 2007 IP
  4. Adulu

    Adulu Peon

    Messages:
    2,791
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks for your replies.

    my database info.
    Database "usexchange"
    Table " ADF,ADP,AED,AFN,AMD,ANG,AOA............etc 190"
    each table has two fied as "date","ex"

    I would like to delete data date(08-21-2007) from one database all of table.
    thank you
     
    Adulu, Aug 23, 2007 IP
  5. webw

    webw Peon

    Messages:
    32
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi,

    Do you have php installed?
     
    webw, Aug 23, 2007 IP
  6. rps111

    rps111 Peon

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Try with DROP command.
     
    rps111, Aug 23, 2007 IP
  7. Adulu

    Adulu Peon

    Messages:
    2,791
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks for you both.
    I am no idea what to do it.

    Is there someone have syntax for phpMySQL?
    for instance
    DELETE FROM `database`.`All table` WHERE `date`='08-22-2007'
     
    Adulu, Aug 23, 2007 IP
  8. flippers.be

    flippers.be Peon

    Messages:
    432
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    rps: drop will drop the whole table, not just one row..

    adulu: I'm not familiar with mysql but on sql server there's a table 'systables' that has the name of each table.. find something similar in mysql.
    then you can make a dynamic query or small script that will loop on the output of a select of each table name and use that as input to make and run a delete query (in php or using sql script using a cursor)
     
    flippers.be, Aug 24, 2007 IP
  9. Clark Kent

    Clark Kent Guest

    Messages:
    122
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Get your table name like below. While looping in table names, execute your delete queries for each table name...

    PS: You can use LIKE '%filter%' in show table command for filtering your tables. Check mysql documantation...

    <?php
    mysql_connect("localhost","root","");
    $result = mysql_query("SHOW TABLE STATUS FROM test;");
    while($array = mysql_fetch_array($result)) {
    echo $array[Name];
    // Do your queries here....
    }

    ?>
     
    Clark Kent, Aug 24, 2007 IP
  10. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #10
    Hi, Try this:
    Save the following as a .php file somewhere on your server.
    Replace username, password, and add all table names where mentioned below.
    Then open script in browser like:
    http://www.yoursite.com/scriptname.php

    <?php
    mysql_connect("localhost","username","password"); //replace username with real username. password with real password.
    @mysql_select_db("usexchange");
    $tables="ADF,ADP,AED,AFN,AMD,ANG,AOA";
    //Enter all table names above seperated with a (,) sign

    $tables=explode(",",$tables);
    $a="";
    foreach($tables as $v)
    {
    if($v!="")
    {
    mysql_query("DELETE FROM $v WHERE date='08-21-2007'");
    $a=$a .','. mysql_affected_rows();
    }
    }
    echo "Deleted: " $a;
    ?>

    Please back up your database first before doing this, incase you want the data back...
    Bye :)
     
    JEET, Aug 24, 2007 IP
  11. Adulu

    Adulu Peon

    Messages:
    2,791
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Thanks for all, JEET especially.

    I got solution from JEET.

    thanks very much
     
    Adulu, Aug 27, 2007 IP