Copying data from one column from one table to another from the same table

2

Hello, I have a question. I need to copy the data from one column of the integer to another column of the decimal type of the same table, this in MySQL. Is it possible? can there be any inconsistencies in the data? And how can I do it?

    
asked by anonymous 09.03.2016 / 01:48

2 answers

3

I do not know if I understand what you want to do, but it seems rather simple. Try the following, see if it helps:

update tabela
set coluna_decimal = coluna_inteira 
    
09.03.2016 / 02:17
1

Just change the type, it will solve the problem:

 ALTER TABLE 'nome_da_tabela' 
 CHANGE 'nome_da_coluna_inteiro' 'nome_da_coluna_decimal' DECIMAL (6,2);

And to copy the data, you can do an insert with select:

SET SQL_SAFE_UPDATES = 0;

INSERT INTO tabela_destino
(campo1, campo2, campo3)
SELECT campo1, campo2, campo3 FROM tabela_origem;
    
09.03.2016 / 05:22