1

Is it bad practice to use a 1-1 relationship between two logically distinct tables: the user details and the user configuration settings? Each configuration record would have a single unique user ID, but they seemed separate enough to warrant two tables rather than one big one. I ask because the WikiBook for my school course said that I should only use 1-Many relationships.

In the User table I will be storing details such as their username, id and authorisation token for an external system. In the Config table I will be storing settings such as whether to show a welcome message, which are changeable through the settings page.

  • 1
    Should give more information on the attributes that you need/want to store in 2 tables. Also can a user have multiple configuration settings? – Marco Dec 12 '15 at 16:08
  • You did say they both have user ID as a key. – paparazzo Dec 12 '15 at 16:11
  • @Marco, updated to explain the purpose of each table. Each user will have exactly one configuration record. – Charlie Harding Dec 12 '15 at 16:20
-1

The attributes should be split in 2 tables because the configuration details are not depending on the user but on the configuration of an external system. If a user can have only 1 configuration then you must use an 1-1 relation. If a user can have multiple configurations then you must use the 1-M relation.

This is the theory. If you want (in case of a 1-1 relation) put all in 1 table than this is also 'allowed'. Remember well that if one day the relation becomes 1-M that you are in problems. This is also why it is preferred to split the information into 2 tables.

|improve this answer|||||
  • To be equivocal: According to theory there's nothing wrong with either a single table or two 1:1 tables (as in "this is also 'allowed'"), and having a separate table "because the configuration details are not depending on the user" is an erogonomic/changeablility reason (as in "This is also why it is preferred to split"). Sadly, typical DBMSs don't let one define the necessary FKs both ways for the 1:1.) (For reasons of not understanding theory.) – philipxy Dec 13 '15 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.