0

ER Diagrams - Can someone please explain modality?

Modality - one at both ends

Above: If there is a module it must belong to a course. And if there is a course we'd really like there to be a module. But is the diagram correct?

The foreign key constraint enforces that if a module exists in the child table then there will be a course in the parent table. But there is no constraint the other way, and obviously you have to create one record before the other.

So, is this more correct (below)?

Modality - one at one end, zero at the other

Or does modality zero mean the FK can be null?

Harley
  • 1,305
  • 1
  • 13
  • 28

1 Answers1

1
  1. The first diagram is correct
  2. No the "O" on the right only mean you allow to have a course with no modules, it's a 0-n relation.

So the first one mean 1-n relation , what you want, but you can't enforce 1-n more than 0-n in SQL. Using "|<" is for documentation, and code implementation, and not for SQL constraint.

The meaning of your convention:
ERD legend

Side note: I prefer the UML "0-n" notation which is more explicit, here would be the result in plantUML: (use planttext.com for the render)
enter image description here

@startuml
title Relationships - Class Diagram
class Courses
class Modules
Courses "1" *-up- "1-n" Modules: Composition
@enduml
pdem
  • 3,880
  • 1
  • 24
  • 38
  • [This site](https://www.calebcurry.com/cardinality-and-modality/) suggests "Modality illustrates whether a column is null or not null". – Harley Feb 11 '20 at 08:14
  • "If there is a module it must belong to a course" that would mean the first diagram is correct as the FK could not be null. – Harley Feb 11 '20 at 08:26
  • @user3121215 A nullable FK means a 0-1 relation, the other side is always 0-n in SQL, as I explained. – pdem Feb 11 '20 at 09:05
  • [This site](https://www.calebcurry.com/cardinality-and-modality/) suggests otherwise. – Harley Feb 11 '20 at 09:07
  • @user312518 you already suggest this site, which is good, and, sorry, but you didn't seem to understand, and don't state what you claim – pdem Feb 11 '20 at 09:19
  • "No the "O" on the right only mean you allow to have no modules," - I don't think that is correct. You could have modules that did not belong to a course if the modality was zero. Also, the question was about ER Diagrams not UML. – Harley Feb 11 '20 at 09:23
  • @user312518 OK, I proposed UML, I will improve my answer, and I suggest you to improve your own answer to add theses elements. – pdem Feb 11 '20 at 09:25