I created every table in an Oracle database but I don't know how implement the relations between tables. Can you help ?
CodePudding user response:
There are plenty of possibilities, but here some selected suggestions:
- A one-to-many association (or aggregation or composition) is often implemented by having the primary key of the "one" appearing as foreign key in the "many". This technique is sometimes called Foreign key mapping.
Example: the primary key ofAddress
table would be an additional foreign key column it theFire
table. - A many-to-many association is generally implemented with an association table, having two foreign keys that correspond to the primary keys of the associated classes. This is sometimes called association table mapping.
Example: You'd have an additional association tablePostFire
having two foreign key columns, one corresponding to the primary key ofPost
and the other to the primary key ofFire
. - An association class is implemented with an association table (see above).
Example: To the table implementingScale
, you'd add two foreign key columns, one with the primary key of Client and the other with the primary key ofFire
. - Inheritance has many many ways of doing it. If you already created 4 tables, then the trick would be to have the primary key of the "parent" appear as foreign key of the "children", with a unique constraint on this value. Another simpler variant could be to reuse the primary key of the parent as primary key of the children. Both of these techniques are called class table inheritance because each class corresponds to a table.
Example: add a foreign key column toFireman
that corresponds the primary key ofUser
.
P.S: Several points, not directly related to your issue:
There is an UML inconsistency between the association-class name
Scale
and the association nameconfirm
. An association class is at the same time the association and the class and cave only have one name.NEVER EVER STORE A PASSWORD IN DATABASE TABLE. Storing a hash code of the password is a much safer approach.