When I should use one to one relationship?

后端 未结 13 1665
面向向阳花
面向向阳花 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:55

    My 2 cents.

    I work in a place where we all develop in a large application, and everything is a module. For example, we have a users table, and we have a module that adds facebook details for a user, another module that adds twitter details to a user. We could decide to unplug one of those modules and remove all its functionality from our application. In this case, every module adds their own table with 1:1 relationships to the global users table, like this:

    create table users ( id int primary key, ...);
    create table users_fbdata ( id int primary key, ..., constraint users foreighn key ...)
    create table users_twdata ( id int primary key, ..., constraint users foreighn key ...)
    

提交回复
热议问题