how to save marital relationship in a database

后端 未结 6 1569
说谎
说谎 2021-01-18 11:28

I have to save this information in a database

Person -> is married to -> Person

Where should I save that information? What is the proper design pattern shoul

6条回答
  •  被撕碎了的回忆
    2021-01-18 12:22

    Here is a hypothetical schema you can use. All people are in a single table, and each person has a unique id. Marriages are in a relationship table, with foreign keys.

    PERSONS
    - ID - INTEGER, PK
    - FIRSTNAME - VARCHAR(20)
    - LASTNAME - VARCHAR(20)
    - SEX - CHAR(1)
    - ... any other fields
    
    MARRIAGES
    - PERSON1_ID - INTEGER, FK
    - PERSON2_ID - INTEGER, FK
    - MARRIAGE_DATE - DATE
    - ANULLMENT_DATE - DATE
    - ... any other fields
    

提交回复
热议问题