Search code examples
database-designumlentity-relationshipclass-diagramerd

ERD relationship - connect 2 optional entity to 1 entity


i have these 3 entities student, staff and discussion.
Their relationship is such that: 1 student can post many discussion; 1 staff can post many discussion; but 1 discussion can only be post by either a student or a staff. Is it ok to have both the foreign key studentID and staffID resides at discussion entity? but doing like this may making every record in it to have 1 null value in either those 2 attribute.enter image description here


Solution

  • Applying Second Normal Form (2NF) will be a guideline:

    First approach: Having a base table for People:
    You may have a People table to store shared properties of peoples. The Student and Staff will be child's of this table, having the Peoples table foreign-key on Discussion table will solve the problem.

    Second approach: Having a base table for Discussion:
    To reduce redundancy you may have a Discussion-Base table ,that would be the base table for two other entities: Staff-Discussion and Student-Discussion tables.
    Discussion-Base table will contain shared properties.
    The solution is appreciated when properties of Staff-Discussion and Student-Discussion tables are varied.
    If they are the same and the only difference is the optional foreign key, the design you have mentioned is efficient.
    Hope this helps.