This is a “web dev best practice” question. I am envisioning a website where users would sign up with a username they would select (revolutionary, I know). They would also enter a valid email address. I would test for the uniqueness of those in the db before allowing the sign-up.
The site is non-commercial in nature, and I don’t need a GUID.
Given this, should I have in my db a separate user ID? I understand vaguely that MySQL might index more efficiently a number-based ID?
Alternatively, should I just use the email address as a unique identifier?
Thanks.
JDelage
User names are typically not unique, and even e-mail addresses can be reused. That’s one reason to have a numeric unique user id.
Another is that when you create a database relation, MySQL has to make a copy of the primary key of the user table. For example, if you have a list of orders per customer. The order would contain the username if that was the primary key. Usernames are longer than integers, which hurts index performance.
If you combine the two, a user that changes his username or email becomes a big problem: you have to rename a primary key, which isn’t easy, and you’d have to update all references to that user from other tables.
But overall, eh, I would hope you have bigger things to worry about, like adding functionality to attract users 🙂