Frage

I'm having some troubles in understanding the modeling of weak entities. My understanding is that a weak entity can exist only in relation of a strong one (i.e. it is "owned" by the strong one). For example if I have the entities Patient and Visit, Patient would be strong and Visit would be weak. What I can't understand is why the PK of Patient should be part of the Visit's PK. Somewhere I have read that a weak entity can not have a PK without containing the strong entity's PK. Why ? Couldn't I simply have the following relational schema

 Patient(Patient_ID(PK),name,surename)
 Visit(Visit_ID(PK),date,description,Patient_id(FK))

and enforce relational integrity on that ? Or should I necessarily have

 Patient(Patient_ID(PK),name,surename)
 Visit(Visit_ID(PK),Patient_id(PK),date,description) ?

Edit after the first answer.

Maybe it was a bad example :-( What about the following situations ? I think that Book and Module are both weak

 Course(Course_ID(PK),name)
 Module(Module_ID(PK),Course_id(FK),name)

 Author(Author_ID(PK),name,surname)
 Book(Book_ID(PK),Author_ID(FK),title)
War es hilfreich?

Lösung

You should probably have something more like this.

Patient(Patient_ID(PK), name, surname)
Visit(Patient_id(PK, FK), start_time(PK), description)

The visit id number serves no useful purpose from the database design point of view. Instead, it increases the likelihood of duplicate data. For example, this

Visit(Visit_ID(PK), Patient_id(PK), date, description)

would allow rows that look like this.

    visit_id  patient_id  date        description
    --
    1         1           2014-05-09  Office visit
    2         1           2014-05-09  Office visit
    3         1           2014-05-09  Office visit
    4         1           2014-05-09  Office visit

(Both structures you posted have the same problem.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top