Is there a need for an unsigned integer id for one to one relations?
There is a table of users (users), there is a table with fields-counters (user_counts)
normal users like everyone
user_counts with fields: id, user_id, comments, likes, votes, notifications
UPD: user_id-unique, there could be 2 records with the same user_id user_counts
I wonder how necessary an unsigned integer id for the table user_counts if everything is still fetching/updates occur on user_id? Maybe it helps some of the internal operations of the database engine be faster or can be removed?
maritza_Marquardt answered on June 8th 19 at 16:35
in this particular case user_counts stores aggregated values comments, likes, votes, notifications and there is clearly no need a surrogate key, because the user_id uniquely identificeret record.
p.s. read what is a surrogate key, why you need it.
thalia.Hermann50 answered on June 8th 19 at 16:37
It is common practice when designing tables. Is primary key is foreign key. In this case, the user_id in the table. The primary key must always be unique. If not ID, then what do you take as the uniqueness of all rows? Otherwise we'll have to take comments or votes or Likes or notifications, or a combination of them. But where is the guarantee that you will not get 2 the same combination of for example from to comment notifications.? Yes, and put the key with the same comment xxx characters? ))
I hope will explain clearly )