I am making an application in which users may create their accounts. I make user email as primary key in user's table. Is this technique is really bad technique? Should I create auto increment integer as primary key?
Asked
Active
Viewed 512 times
2
-
3I'd use an int as primary key and put a unique index on the email column. – Tim Schmelter Mar 11 '15 at 08:36
-
1It's not a good idea... People change a-mail addresses once in a while. – jarlh Mar 11 '15 at 08:37
-
Are users never allowed to change which email address is associated with their account? – Damien_The_Unbeliever Mar 11 '15 at 08:37
-
I would suggest use of incremental int or guid as primary key and e-mail as unique index. This will be safer, easier and more convenient. – user3021830 Mar 11 '15 at 08:37
-
Very bad idea, the speed of cross table lookups would decrease dramatically I'd imagine – Sayse Mar 11 '15 at 08:38
-
Also foreign key columns will make a lot of overloads, because of data type... – Mohi Mar 11 '15 at 08:42
1 Answers
7
Yes, it is a terrible idea. An email is something long (so your key is longer than necessary), and it isn't immutable. I've changed at least three emails in the last ten years (providers closed).

xanatos
- 109,618
- 12
- 197
- 280
-
-
2I think that the main problem with email addresses as primary key is that you also have them as foreign-key, everyhwere. – Tim Schmelter Mar 11 '15 at 08:43
-
@TimSchmelter Yes. Clearly if you have a single table in the DB then you can use the email as a primary key :) But it would be a very very simple DB – xanatos Mar 11 '15 at 08:47