有人可以帮助我如何在phpmyadmin中运行命令,这将删除数据库中具有前缀"test_"的所有列.
我对MYSQL不是很好,所以我甚至不知道从哪里开始,任何帮助都会受到赞赏.
非常感谢.:)
要从表中删除列,请使用以下语法:
alter table <tablename> drop column <columnname>
Run Code Online (Sandbox Code Playgroud)
要查找以test_开头的数据库中表中的所有列,请执行以下操作:
select column_name
from INFORMATION_SCHEMA.columns
where table_name = <table_name> and
table_schema = <schema_name> and
left(column_name, 5) = 'test_' -- not using "like" because '_' is a wildcard char
Run Code Online (Sandbox Code Playgroud)
如果你手动执行此操作,我建议运行以下查询,然后将结果粘贴到mysql查询界面:
select concat('alter table ', table_name, ' drop column ', column_name)
from INFORMATION_SCHEMA.columns
where table_name = <table_name> and
schema_name = <schema_name> and
left(column_name, 5) = 'test_'
Run Code Online (Sandbox Code Playgroud)
您可以在代码中执行类似操作,方法是运行查询,返回结果,然后将每行作为查询运行.
| 归档时间: |
|
| 查看次数: |
3821 次 |
| 最近记录: |