Az alap valami ilyesmi lenne
SELECT concat('DROP TABLE IF EXISTS ',table_name,';') as torol
FROM information_schema.tables WHERE table_schema = 'ADATBAZIS' AND table_name LIKE '%sf%'
Itt hasznalhatsz REGEXP et is vagy LENGTH, MID stb
Pl ha az sf mindig 4. akkor AND substring(table_name,3,5)='sf'
Majd a kapott eredmenyt futtatod, vagy simma SQL ben phpmyadminban vagy PHP.
itt a PHP verzio:
PHP kód:
<?php
mysql_connect('localhost','USER','PASS');
$db = 'ADATBAZIS'; //ahol a tablak vannak
$sql = "SELECT table_name as torol FROM information_schema.tables
WHERE table_schema = '$db' AND table_name LIKE '%sf%'";
$res = mysql_query($sql); if (!$res) { die("$sql <br><br> mysql_errno() : mysql_error()"); }
while ($row = mysql_fetch_array($res)){
$query = "DROP TABLE IF EXISTS `$db`,`{$row['torol']}`";
mysql_query($query);
echo $row['torol'] . '<br />';
}
mysql_close();
?>
Könyvjelzők