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


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to