patternMinor
Entity set that has a relationship with itself
Viewed 0 times
itselfwithhasthatsetentityrelationship
Problem
I have this ER model that I am having difficulty understanding, since there is an entity set that has a relationship with itself. I am trying to understand two questions:
1) Can a child be born before the parent?
2) Can a person to be a child of themselves?
For 1) I don't think this is possible, because the parentID field would be null
For 2) Since this is a many to one relationship, I don't see why this can't be true, as long as the person isn't a child of someone else.
1) Can a child be born before the parent?
2) Can a person to be a child of themselves?
For 1) I don't think this is possible, because the parentID field would be null
For 2) Since this is a many to one relationship, I don't see why this can't be true, as long as the person isn't a child of someone else.
Solution
There's nothing in the ERD to constrain the model either way. Without suitable constraints, a child could be recorded as being born before his/her parent, a person could be their own child or parent, and cycles over any number of generations could exist.
For example, assuming the ERD is implemented as:
we could record the following sets of rows:
There's nothing in the ERD to prevent any constraints either. As it stands, I would have to answer "yes" or "it depends on what unstated constraints you assume or implement" to both questions. If such constraints were required, I would recommend stating them explicitly.
For example, assuming the ERD is implemented as:
Person (personId PK, dateOfBirth, name, gender)
ChildOf (personId PK/FK, parentId FK)we could record the following sets of rows:
Person (1, 2000-11-01, John, Male) ChildOf (1, 2)
Person (2, 1970-05-23, Jane, Female) ChildOf (2, 4)
Person (3, 1985-01-11, Jack, Male) ChildOf (3, 3)
Person (4, 1950-11-01, Joan, Female) ChildOf (4, 1)There's nothing in the ERD to prevent any constraints either. As it stands, I would have to answer "yes" or "it depends on what unstated constraints you assume or implement" to both questions. If such constraints were required, I would recommend stating them explicitly.
Code Snippets
Person (personId PK, dateOfBirth, name, gender)
ChildOf (personId PK/FK, parentId FK)Person (1, 2000-11-01, John, Male) ChildOf (1, 2)
Person (2, 1970-05-23, Jane, Female) ChildOf (2, 4)
Person (3, 1985-01-11, Jack, Male) ChildOf (3, 3)
Person (4, 1950-11-01, Joan, Female) ChildOf (4, 1)Context
StackExchange Database Administrators Q#162539, answer score: 5
Revisions (0)
No revisions yet.