Q:

Pulling a field from a Foreign Key into table

I'm having a bit of a brain fart here.  I have a MySQL database with vehicle information.  In it there is a table Vehicles, with a Foreign Key for VehicleMake and VehicleModel.  I've decided to remove the Model FK and just have the Vehicle Model as a varchar field in the Vehicle Table. Now I'm trying to figure out how to pull the models for the existing entries in the table.
Table 'Vehicle' (id, vehicleMake, vehicleModel, model)
Table 'VehicleModels' (id, modelName)

So basically I'm trying to figure out a query that will pull the data from VehicleModels.modelName into Vehicle.model for each row in my Vehicles table.

A:

Here is the update statement you would want to use:
UPDATE Vehicle, VehicleModel
SET Vehicle.VehicleModel = VehicleModel.modelName
WHERE Vehicle.model = VehicleModel.id

After this, you would also want to remove the FK constraint from Vehicle(model) on VehicleModel(id) once your code is providing the application vehicleModel data instead of model information.
ALTER TABLE Vehicle DROP FOREIGN KEY FK_Vehicle_model_VehicleModel_id;

This would be how I name the foreign key, your name may vary.

