You have to understand the nature of your DB table before deciding what column(s) should be chosen to be the primary key.
Here is a definition of Primary Key from Techopedia:
A primary key is a special relational database table column (or
combination of columns) designated to uniquely identify all table
records.
A primary key’s main features are:
- It must contain a unique value for each row of data.
- It cannot contain
null values.
A primary key is either an existing table column or a
column that is specifically generated by the database according to a
defined sequence.
In this case, it seems like your table is storing measurement information about a user, who is allowed to have multiple measurements on different days (e.g. George
had a measurement on 24/09/2016
and then another one again on 25/09/2016
), but not on the same day.
In this case, the primary key really should have two columns -- Username
and Date
.
Do not confuse primary key from unique key or just key (index). Here is an SO discussion about the topic.
By the way, if you want to further allow the same user to upload more than one measurements on the same day, then you have two solutions:
- Add a surrogate key column (probably called
id
) that uniquely
identifies each measurement records (see Wikipedia discussion). Use
this surrogate key as the primary key of your table.
- Make your
Date
column a type of Datetime
rather than just Date
.
You still have to limit that there can be no more than one
measurements from the same user for any given Datetime
value (in MySQL
the data type of DATETIME
support fractional second (up to
microseconds precision))
Personally I think the approach of using a surrogate key is the safest in the long run.