Referencing two attributes of a table to a primary key of another table

0

How are you doing?

You see, I'm making a logbook for private pilots. Among all the resulting entities (tables), I have two: flight and airport. This Airport table, consists of: ID, ICAO Code, Name and the FK of the city.

Among the fields of the Flight table there are two in particular: Airport_Exit and Airport_Reach. There is also an FK of the airport table.

However, how can I structure the database so that I do not have to, for example, make two additional tables: Aeropuerto_Llegada and Aeropuerto_Exit (both would contain exactly the same data, so I see it as redundant)?.

Thank you very much in advance.

Greetings!

    
asked by EstebanP 21.09.2017 в 22:53
source

1 answer

-1

Remember that the FK refer to an external table to validate that the data that is entered in that field exists in the other table, with the option to accept or not Null.

What you have to have is two FK one for the field Aeropuerto_Salida and another one for Aeropuerto_Llegada , both referring to the field of the table Aeropuertos .

I recommend that your references always be primary keys and with the options of ON UPDATE CASCADE ON DELETE RESTRICT , which allows you to update your references and block the elimination of referenced records.

    
answered by 22.09.2017 в 20:43