How to implement total disjoint specialization in database?

前端 未结 2 785
生来不讨喜
生来不讨喜 2020-12-18 14:47

Say there is a database for students and professors (a very simple one) and the relational database is the following:

GradStudent (_id_, name, gradStuff)
Und         


        
2条回答
  •  悲&欢浪女
    2020-12-18 15:19

    If by "fetch the student id for the Teaches table", you mean you want Teaches.stud_id to be a FK that references "GradStudent or Undergradstudent as is the case", you can't. The target of a FK must be a key of a table that is not a view. You have no such table, ergo you have no such key either.

    Only way I see is to code a trigger that does the check upon inserts/updates to Teaches.

提交回复
热议问题