Search code examples
database-designerd

ERD to keep or not to keep a one to one relationship


I am designing an ERD diagram for an online retail store. I have a customer table with all relevant details stored within. I also have a customer login details table that just contains; email and password fields. The only relationship I can see available is a one to one, with email being a link between the 2.

my question is am I better off absorbing this table into the customer one? or is there any benefit in keeping it separate?

I would appreciate any help guys as databases are not my strong point


Solution

  • Yes for a one-to-one like that I would look to have all the details in one table.

    Some exceptions might be:

    • Performance. If there are hundreds of thousands of users you would want the main tables to be as 'thin' as possible and sometimes this means moving singular details out to a 1-to-1 table.

    • Security in the database. Having the password in a separate field from other user details could let you put a lot more work into protecting that table without slowing down or preventing access to the user details table. user details will have personal info but almost nothing is more important than the password which give an imposter access to actually do stuff (including easily finding out more personal info just be fake-logging-in).

    • Security for the ERD. Since your question has ERD in the title, showing the ERD with the ability to actually omit the table name and column names with password will be much easier if they are in a separate table and this may be required when sharing the ERD, doing demo's, etc.

    • Requirement for multiple logins. Sites like Stack Exchange let you associate multiple accounts to one master 'login'. In these scenarios having username password separate makes as that is really a one-to-many relationshiop. So if you're confident that the one-to-one relationship will never change and/or you're working on an agile process that isn't anticipating features before they're actually made, than you don't need it separately.