扫码关注官方订阅号
删除某个表我知道是使用
DROP TABLE
这种命令,如果我只想删除以WP_开头的表呢该怎么写SQL呢?
WP_
小伙看你根骨奇佳,潜力无限,来学PHP伐。
mysql的drop table不支持通配符,所以,你的需求没办法用一条SQL语句搞定,你有两个选择:
for table_name in `mysql -uroot -e 'use your_db; show tables' | grep wp_` do mysql -uroot -e 'use your_db; drop table $table_name if exists' done
只能拼接SQL语句然后动态执行了。。。
set @str = (select concat('drop table ', group_concat(table_name separator ','),';') from information_schema.tables where table_schema = 'your_schema' and table_name like 'WP__%'); prepare stmt from @str; execute stmt; deallocate prepare stmt;
可以参考下 http://stackoverflow.com/questions/54...
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
mysql的drop table不支持通配符,所以,你的需求没办法用一条SQL语句搞定,你有两个选择:
只能拼接SQL语句然后动态执行了。。。
可以参考下 http://stackoverflow.com/questions/54...