I am creating a database and I am not sure about one of my tables. This table stores the users that are in each game, so one entry per user per game. The user is identified by their user_id
which is a 36 character UUID4, and the game is identified by a session_id
which is an 8 character alphanumeric string such as "ABK2RXN4". Currently, I have created an additional field just called id
which is an integer that auto increments, and I have set that to be the primary key. These are the only 3 fields.
Since the combination of the session_id
and the user_id
will always result in a unique outcome, should I instead use those two as the composite private key and remove the id
field?
Thanks.
EDIT:
Do things change if we have a more complicated table that will require more fields? Take this table for example.
| id | voter | voting_for | round | category_id | acceptable |
|-----|----------|------------|----------|-------------|------------|
| int | char(36) | char(36) | smallint | int | boolean |
This is to do with votes within a game. Essentially after each round, the users in the game will vote on the answers of the other users within the game. So each entry has the user_id of the voter
, the user_id of the person they are voting_for
, the current round
, the category_id
of the category within the game and whether or not they agreed with the answer, acceptable.
So, you could make a composite primary key using voter
, voting_for
, round
and category_id
. Is this any worse just because there are more fields, or should I still use the composite key instead of the existing auto increment id
?