When I should use one to one relationship?

后端 未结 13 1651
面向向阳花
面向向阳花 2020-11-27 11:32

Sorry for that noob question but is there any real needs to use one-to-one relationship with tables in your database? You can implement all necessary fields inside one table

13条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 11:48

    As with all design questions the answer is "it depends."

    There are few considerations:

    • how large will the table get (both in terms of fields and rows)? It can be inconvenient to house your users' name, password with other less commonly used data both from a maintenance and programming perspective

    • fields in the combined table which have constraints could become cumbersome to manage over time. for example, if a trigger needs to fire for a specific field, that's going to happen for every update to the table regardless of whether that field was affected.

    • how certain are you that the relationship will be 1:1? As This question points out, things get can complicated quickly.

提交回复
热议问题