In the mysql
, the table "information_schema.Columns" has the record of all columns in all tables, if you make a select you will find the table names:
SELECT TABLE_NAME
FROM information_schema.columns
WHERE column_name = 'id_usuario';
If you want to delete table columns from there you need to do two things:
I don’t have now how to assemble a functional example now, but can create a code process in this structure below to make these steps:
DECLARE nome_tabela VARCHAR(500);
DECLARE cursor_tabelas CURSOR FOR SELECT TABLE_NAME FROM information_schema.columns WHERE column_name = 'id_usuario';
OPEN cursor_tabelas;
LOOP
FETCH cursor_tabelas INTO nome_tabela;
SET @drop_command = CONCAT('ALTER TABLE ',nome_tabela,' DROP COLUMN id_usuario');
PREPARE stmt FROM @drop_command;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT nome_tabela;
END LOOP;
CLOSE cursor_tabelas;
Isn’t it easier to write a small program, or script, with 100 commands? Of course, the question itself is valid, as a curiosity.
– epx
@epx I thought the same thing because it seems to be a task that would be done only 1x. Then never again.
– Danizavtz