From database diagram to relational representation

Rule 1: a class translates to a relation

The class below:

_uml/rule1.pu

Correspond to the relation:

Agent(name: String, #secretCode: String, age: int)
Unit(#name: String, location: String)

Rule 2: n..* to m..* relationships

The association Belong below:

_uml/rule2.pu

Correspond to the relation:

Belong(#unitName=>Unit.name, #secretCode=>Agent.secretCode, years: int)

And the constraint (as there is a 1..*):

secretCode IN Belong

➑️ An alternative syntax for primary keys is #unitName=>Unit(name).


Rule 3: n..* to 0..1 or 1 relationships

The association Belong below:

_uml/rule3.pu

Correspond to the relation:

Agent(name: String, #secretCode: String, #unitName: Unit.name, years: int)
Unit(#name: String, location: String)

Unit in Agent

What rules to apply?

  • Given A(0..1) and B(???), the identifier is A is added in B (πŸ”„οΈ)
  • Given A(1) and B(???), the identifier of A in B is NOT NULL (πŸ”„οΈ)
  • Given A(???) and B(1..*), every identifier in A must appear in B at least once(πŸ”„οΈ)
  • The association class goes to the side with n..*

Rule 4: 1 or 0..1 to 0..1 or 1 relationships

Missing.


Rule 5: self relationships

A self-relationship is the same as a relationship between two classes. Refer to rules 2 to 4.


Rule 6: generalizations

Missing.


Rule 7: n-ary associations

Missing.