How to Set Customer Table with Multiple Phone Numbers? - Relational Database Design

前端 未结 2 1945
北荒
北荒 2021-02-10 13:49
CREATE TABLE Phone
(
phoneID - PK
.
.
.
);

CREATE TABLE PhoneDetail
(
phoneDetailID - PK
phoneID - FK points to Phone
phoneTypeID ...
phoneNumber ...
.
.
.
);

CREATE T         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-10 14:39

    As mrjoltcola already addressed the normalization, I'll tackle the problem of having a record in phone and no record in phone detail.

    If that is your only problem there are three approaches:

    1) do not delete from detail table but from phone with CASCADE DELETE - gives a delete from two tables with single SQL statement and keeps data consistent

    2) have triggers on the detail table that will delete the parent automatically when last record for a parent is deleted from the child (this will not perform well and will slow down all deletes on the table. and it is ugly. still it is possible to do it)

    3) do it in the business logic layer of the application - if this layer is properly separated and if users(applications) will be modifying data only through this layer you might reach desired level of consistency guarantee

提交回复
热议问题