update from a vehicle plate code

Asked

Viewed 56 times

-1

I have 4 tables, the problem is that I have in the table the white color and I want to change the color only of a car that has the white color, changes of all cars with the 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';

MER

2 answers

0


This is because you are setting the color in a table that has a relationship with the tb_modelo_vehicle table. Just when you update the color table, the table tb_modelo_vehicular, which has a fk for the table tb_cor_vehicular, references this color for all related models. To define the color of a specific vehicle, you would have to reshape your tables and post a reference for the table tb_vehicle in the table tb_vehicle instead of tb_vehicle. So you could do the following update:

UPDATE tb_veiculo v set v.cd_cor_veiculo = 1
where v.cd_placa_veiculo = 'BBB002';

-1

On the line of update use the clause WHERE to filter what you are wanting. In case, change only white color.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.