update from the license plate code of a vehicle

-1

I have 4 tables, the problem is that I have in the table the white color and I want to change the color of only a car that has white color, changes of all cars with white color.

update tb_veiculo v join tb_marca_veiculo ma on v.cd_marca_veiculo=ma.cd_marca_veiculo join tb_modelo_veiculo m on ma.cd_marca_veiculo=m.cd_marca_veiculo join tb_cor_veiculo c on m.cd_cor_veiculo=c.cd_cor_veiculo set m.cd_cor_veiculo='1' where m.cd_cor_veiculo='0' and v.cd_placa_veiculo='BBB002';

    
asked by anonymous 09.09.2018 / 23:53

2 answers

0

This is because you are setting the color in a table that has a relationship with the table tb_modelo_veiculo. As soon as you update the color table, the tb_modelo_veiculo table, which has a fk for the tb_cor_veiculo table, reference this color for all related models. To set the color of a specific vehicle, you would have to reshape your tables and put a reference for the tb_cor_veiculo table in the tb_veiculo table in place of the tb_modelo_veiculo. So you could do the following update:

UPDATE tb_veiculo v set v.cd_cor_veiculo = 1
where v.cd_placa_veiculo = 'BBB002';
    
10.09.2018 / 00:21
-1

At the update line, use the WHERE clause to filter what you want. In this case, change only the white color.

    
10.09.2018 / 00:08