From database diagram to relational representation
Rule 1: a class translates to a relation
The class below:
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:
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:
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)
andB(???)
, the identifier is A is added in B (ποΈ) - Given
A(1)
andB(???)
, the identifier of A in B is NOT NULL (ποΈ) - Given
A(???)
andB(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.