I don’t know any "simple" way to do this, but through this algorithm I believe that will have the expected result:
SET @row_number := 0;
INSERT INTO tabela_tmp
SELECT (@row_number:=@row_number + 1) AS num, CONCAT('update ', TABLE_NAME, ' SET ', CONCAT(GROUP_CONCAT(CONCAT(COLUMN_NAME, '=LOWER(', COLUMN_NAME, ')')), ';'))
FROM INFORMATION_SCHEMA.COLUMNS
GROUP BY TABLE_NAME;
SET @id_tabela:=1, @total:=(SELECT COUNT(*) FROM tabela_tmp);
WHILE @id_tabela <= @total DO
SET @comando = (SELECT comando FROM tabela_tmp where num = @id_tabela);
PREPARE myquery FROM @comando;
EXECUTE myquery;
SET @id_tabela = @id_tabela + 1;
END WHILE;
tabela_tmp
is a table that will store the update commands of each table (one in each row). In the assembly of this commando, I used the CONCAT()
for the structure ("update table ...") and GROUP_CONCAT()
to take all fields from the table and organize them in a row.
Done that, in a loop just load the commands and run them.
Working example
update Table SET value = LOWER(value)
– Alvaro Alves
@Gustavo, I published an answer, see if it helps. I hadn’t seen anything like this yet.. gave a nice job, but I liked the code =]
– rLinhares
you want to convert the column name or value?
– rray
@rray the values!
– Gustavo
@rLinhares didn’t work...
– Gustavo
@Did Gustavomacielsetta see if there were any errors or if he updated any data? Did he look at the fiddle?
– rLinhares
@Since the fiddle did not work. And in my bank tbm does not say that there is no table table_tmp. I created the table with the same columns but continued to show error...
– Gustavo
@The fiddle wasn’t working. But I checked now and he’s okay, but I have no idea how to apply this solution to my bank, I mean, I’m still the same...
– Gustavo
What’s wrong with the bank? Why can’t you apply??
– rLinhares