Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 494
Brad Thiessen Avatar asked Sep 24 '13 21:09

Brad Thiessen


People also ask

How is ER diagram converted into a table?

Reduction of ER diagram to Table. The database can be represented using the notations, and these notations can be reduced to a collection of tables. In the database, every entity set or relationship set can be represented in tabular form. Entity type becomes a table.

What will an entity in an ERD translate into in a database?

An entity type within ER diagram is turned into a table. You may preferably keep the same name for the entity or give it a sensible name but avoid DBMS reserved words as well as avoid the use of special characters. Each attribute turns into a column (attribute) in the table.

What is a relationship in entity relationship diagram?

An entity relationship diagram (ERD), also known as an entity relationship model, is a graphical representation that depicts relationships among people, objects, places, concepts or events within an information technology (IT) system.

What is the relationship between entities and tables?

An entity resides in a table, it is a single set of information, i.e: if you have a database of employees, then an employee is an entity. A table is a group of fields with certain parameters. Basically everything is stored in a table, entities goes into tables.


Video Answer


1 Answers

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.

like image 186
Marco Bonzanini Avatar answered Sep 22 '22 04:09

Marco Bonzanini