-1

I've read here that using email address field as a primary key for managing user database is a very bad idea.

How, and why? The book doesn't delve into the reasons. How can using email field as a primary key for a table be so deleterious? Are there some horrible long-term implications that I do not see?

Edit: This question is about performance issues of string comparison, however, that does not concern me (at least for this question). I am interested in long-term implications of using email as a primary key. From experience, does it generally cause problems in the future?

tornikeo
  • 915
  • 5
  • 20
  • Does this answer your question? [Use email address as primary key?](https://stackoverflow.com/questions/3804108/use-email-address-as-primary-key) – Daniel Jacob Aug 24 '20 at 08:14

2 Answers2

2

Well, I guess the most obvious (not performance-related) reason is that users may want (or need) to change their email addresses.

If the email address is the primary identifier for user accounts this can get confusing pretty quickly.

From a domain modeling view, email-addresses are commonly handled as attributes of persons/users, just as a user name is. While user name changes can probably be reasonably not allowed, email addresses are rather likely to change at some point (user loses access to the account, the organization that maintained the account retires, etc.).

Also, an email address does not need to be eternally assigned to the same real-life person. joe@example.com could be owned by "Joe Miller" in 2005, "Joe Carlos" in 2013, and by "Joeberto Joeman" from 2020 onwards.

This possible need for change is IMO the main reason why email addresses don't make good primary keys.

Lars Br.
  • 9,949
  • 2
  • 15
  • 29
  • 1
    Very good point. Can't stress that enough: addresses change and it's a good idea to support that easily. Another example is changing names after a marriage, which is pretty common in many parts of the world. Typical firstname.lastname@corp email addresses are updated all the time due to this... – martinspielmann Aug 24 '20 at 11:10
0

There are a few attributes you look for in a primary key.

The problems with "email address" are

  • it's not possible to guarantee it's unique - an email address may be used by a group of people at the same time, or different people over time.
  • it's not immutable - the same person may change emails over time; this would require you to update all the tables with foreign key relationships
  • it does not uniquely identify a person - one person may have multiple email addresses
Neville Kuyt
  • 29,247
  • 1
  • 37
  • 52