List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 26 2002 4:42am
Subject:Re: Dropping tables
View as plain text  
At 22:20 -0600 3/25/02, Steve Buehler wrote:
>Thank you.  I am still not an expert yet at MySQL and/or PHP.  I 
>learn something new everyday.  At least this list doesn't knock 
>people down for asking questions that could be found by either a 1 
>minute or a 1 month search on the web.  I will try this out in the 
>morning.  I see no reason why your suggestion would not work.  So I 
>will thank you before I even try it. :)

If you're using PHP, you should be able to use a function like this:

function delete_tables_with_pattern ($conn_id, $pat)
{
     $query = "SHOW TABLES LIKE '$pat'";
     $result_id = mysql_query ($query, $conn_id);
     if ($result_id)
     {
         $table = array ();
         while (list ($name) = mysql_fetch_row ($result_id))
             $table[] = $name;
         mysql_free_result ($result_id);
         if (count ($table) > 0)     # some tables were named
         {
             $query = "DROP TABLES " . join (",", $table);
             mysql_query ($query, $conn_id);
         }
     }
}

Call it like this:

delete_tables_with_pattern ($conn_id, "division1s%");

However, before actually using it as shown above, you probably want to
replace the second mysql_query() with a print statement. :-)


>
>Thanks
>Steve
>
>At 09:58 PM 3/25/2002, you wrote:
>>At 16:40 -0600 3/25/02, Steve Buehler wrote:
>>>Is there anyway to drop a group of tables with a wildcard in 
>>>MySql? I have tried:
>>>DROP TABLE IF EXISTS division1s*
>>>and
>>>DROP TABLE IF EXISTS division1s(*)
>>>but neither one works.  I am hoping that there is a good useable 
>>>answer to this.
>>
>>The syntax described in the manual shows what what you want to do is not
>>supported.  You can't do it directly in SQL.
>>
>>But depending on the context in which you're issuing the statement,
>>you can achieve the objective by other means.  For example, if you're
>>using some kind of API, you can use SHOW TABLES LIKE 'division1s%',
>>then use the resulting list of tables to construct a DROP TABLES
>>statement that drops the tables.
>>
>>>
>>>Thanks in advance
>>>Steve Buehler

Thread
Dropping tablesSteve Buehler25 Mar
  • Impact of Free ORACLEMadProfessor25 Mar
    • Re: Impact of Free ORACLEDan Nelson25 Mar
    • RE: Impact of Free ORACLERichard Forgo25 Mar
      • RE: Impact of Free ORACLEMadProfessor26 Mar
        • RE: Impact of Free ORACLETim Buchalka26 Mar
        • Re: Impact of Free ORACLEMichael Bacarella26 Mar
        • RE: Impact of Free ORACLEFrancesca Shiekh26 Mar
          • RE: Impact of Free ORACLECharles McGrotty26 Mar
    • Re: Impact of Free ORACLEFrancesca Shiekh25 Mar
    • Re: Impact of Free ORACLEGabriel Ricard26 Mar
    • Re: Impact of Free ORACLEJerry Winegarden26 Mar
  • hierarchical struture into mysqlDavid yahoo26 Mar
    • RE: hierarchical struture into mysqlKevin Fries27 Mar
  • Re: Dropping tablesPaul DuBois26 Mar
    • Re: Dropping tablesSteve Buehler26 Mar
      • Re: Dropping tablesPaul DuBois26 Mar
RE: Impact of Free ORACLEAaron Rutledge25 Mar
  • Re: Impact of Free ORACLEjay downs26 Mar
RE: Impact of Free ORACLERBRoa26 Mar
RE: Impact of Free ORACLEJoe Hoffman26 Mar
RE: Impact of Free ORACLEjwubbel26 Mar
  • RE: Impact of Free ORACLEMadProfessor26 Mar
    • RE: Impact of Free ORACLERon Jamison26 Mar
  • RE: Impact of Free ORACLEFrancesca Shiekh26 Mar
RE: Impact of Free ORACLERobert Cross26 Mar
RE: Impact of Free ORACLEJonathan Hilgeman26 Mar