My web application will have various types of users: a root user, sys-admins, customers, contractors, etc. I'd like to have a table "User" that will have the columns "Username", "Password", and "Role" with role being one of the aforementioned roles. I will, for example, also have a table called "Customer" for storing customer-specific attributes.
Here's my question. Since all usernames will be unique, I could use the username as the primary key for the User table. Would it make more sense, though, to create a "User ID" column and use it rather than the Username column as the PK? There are many other tables that will use this User PK as a foreign key and I would think that, from a performance standpoint, it will be faster to compare user IDs rather than username text strings.
Thank you for your response.
Why you need a unique username for every account. The main issue with usernames is that they are public, not hidden like your passwords. Reusing the same username makes it easier for malicious actors to build your online profile. It also makes it easier for advertisers and random people to find and track you online.
If your username will be visible to others (or you just want to have some fun with your usernames), choose one with an interesting persona — maybe a screen name, Twitter name, medieval name, or elf name. Choose a random username that's easy to say or read from one to 50 characters.
Unique User ID means a string of characters that identifies a specific user and which, in conjunction with a password, passphrase or other mechanism, authenticates a user to an information system.
I would create the userid because while usernames might be unique, they are not generally unchangeable and I would prefer not to have to change thousands or millions of records because HLGEM wanted to become HLGEM_1. Further joins on integers are faster.
This is the old natural vs. surrogate key debate.
In a nutshell, nothing is cut-and-dry and you'll need to balance between competing interests:
In the case of usernames...
...so the surrogate key is probably justified in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With