I have a web application, I have a concept of users who are likely to go into the user table, for example:
table: user username (varchar 32) | email (varchar 64) | fav_color | ...
I would like the username and email address to be unique, that is, I cannot allow users to have the same username or the same email address. I see that in examples of tables of this type, the primary key is always entered with auto-increment.
Not sure why this is done, does it somehow speed up queries using foreign keys? For example, let's say I have another table like:
table: grades username (foreign key?) | grade
Is it inefficient to use a username as a foreign key? I want to make queries like:
SELECT FROM grades WHERE username = 'john'
so I think it would be faster to do an integer search for the database ?:
SELECT FROM grades WHERE fk_user_id = 20431
thanks
source share