Question

I am currently trying to design a social network type of website and this is the class diagram
that I have so far

enter image description here

at the moment I have userId and username in separate tables because I wanted to normalize these tables but now I am not sure why do I need the userId attribute? I have done research and a lot of similar projects have this attribute but I don't get why? if the username is already going to uniquely identify a particular user.

By the way I am aware I have a problem with the requests table because at the moment with the attributes given I cannot identify a primary key Thanks

Was it helpful?

Solution

Two big reasons I can think of:

  1. Optimization. SQL databases typically perform far better when using integer primary keys than varchar ones. Lookup-something-by-user is one of the most common operations in this environment, so this has real performance implications. Many DBAs don't like GUID/UUIDs as PKs for exactly this reason.
  2. Nothing dictates that a username must uniquely identify users. Case in point: Stack Exchange user handles don't have to be unique, and are freely editable.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top