Entity Relationship Diagram. How does the IS A relationship translate into tables?

Brad Thiessen picture Brad Thiessen · Sep 24, 2013 · Viewed 52.8k times · Source

My drawing of a simple ER diagram

I was simply wondering, how an ISA relationship in an ER diagram would translate into tables in a database.

Would there be 3 tables? One for person, one for student, and one for Teacher?

Or would there be 2 tables? One for student, and one for teacher, with each entity having the attributes of person + their own?

Or would there be one table with all 4 attributes and some of the squares in the table being null depending on whether it was a student or teacher in the row?

NOTE: I forgot to add this, but there is full coverage for the ISA relationship, so a person must be either a studen or a teacher.

Answer

Marco Bonzanini picture Marco Bonzanini · Oct 8, 2013

Assuming the relationship is mandatory (as you said, a person has to be a student or a teacher) and disjoint (a person is either a student or a teacher, but not both), the best solution is with 2 tables, one for students and one for teachers.

If the participation is instead optional (which is not your case, but let's put it for completeness), then the 3 tables option is the way to go, with a Person(PersonID, Name) table and then the two other tables which will reference the Person table, e.g. Student(PersonID, GPA), with PersonID being PK and FK referencing Person(PersonID).

The 1 table option is probably not the best way here, and it will produce several records with null values (if a person is a student, the teacher-only attributes will be null and vice-versa).

If the disjointness is different, then it's a different story.