Command to drop all columns in a database that have prefix test_ to run

后端 未结 4 493
一整个雨季
一整个雨季 2020-12-16 08:08

How I can run a command in phpMyAdmin which will drop all columns in a database that have the prefix test_.

4条回答
  •  伪装坚强ぢ
    2020-12-16 08:37

    I would like to explain or simplify this answer for those like me who were having trouble with this.

    I was having trouble dropping a column with the name 'seq' in all tables in my database 'demo'.

    You can create a selection with the commands formatted for each table using something like this:

    Select concat('alter table ', table_name, ' drop column ', 'seq;')
    from (select table_name
    from INFORMATION_SCHEMA.tables
    where table_name = table_name and
    table_schema = 'demo') as t
    

    This creates the alter table command for each table in the 'demo' database.

    You have to select the result, copy it, and paste it back into the query editor.

    It's a two step process, but if you have to do this several times, save the commands in a text file to run again later.

提交回复
热议问题