database-design

How to store multiple email addresses


I need to store a bunch of email addresses each having a label (primary business, secondary business, etc.)

I have 2 approaches:

  1. Store them as columns email1, email2, email 3 - which limits the flexibility in having any number of emails. It also limits flexibility to store additional details related to email e.g. the date of activation of the email, etc.
  2. Store them as rows - this allows me to have any number of email addresses and also allows me to have specific properties.

I tend to lean towards solution 2 - any opinions?


Solution

  • If the email types are cast in stone (etc business and personal), you can put them as columns, but name the columns accordingly. That means, no Email1, Email2, Email3 fields, but a PersonalEmail and BusinessEmail field.

    If the types and the number of the email addresses is flexible, always use the second option, with the caveat that this will negativelly affect the UI. While it's easy to put two or three text-boxes to display the first and second email, for an unknown number of emails, you'll need to use something like a grid or a list, that might not look ideal.


    However, in my experience, the usual use case for this type is that most of the users (99%) will have just a single email address/phone number/street address, but you have some outliers that has like 7 emails entered.

    If that's the case you can go for a hybrid approach. Use one of the email addresses (the email address in most situations) as a primary adress and store it into the original table, and add an additional boolean field to the table that will show if the user has additional email addresses (which will be stored into another table).

    That way you can get the best of both worlds, a simple way to see a persons email-address, without using joins, and a flexybility when someone decides to put every email address he ever owned into the app.