I'm trying to better understand the use of Primary Keys in SQL (any flavour). I'm having a bit of a block on understanding where they can be used.
From W3schools SQL Primary Key Definition a primary key is defined as:
The PRIMARY KEY constraint uniquely identifies each record in a table.
Primary keys must contain UNIQUE values, and cannot contain NULL values.
If I have the following table, where Student_id is the column to which I want to make a primary key (so use it to uniquely identify a record in a table):
Student_id subject_studied
E1 maths
E1 science
E1 english
B2 arts
V3 gym
C5 science
C5 maths
I assume that making Student_id the primary key is allowed in this case, as each record can be uniquely identified.
However if we take a different but similar table, with lots of duplicate records:
Student_id subject_studied
E1 science
E1 science
E1 science
B2 arts
V3 gym
C5 science
C5 science
then Student_id cannot be a primary key as it does not uniquely identify each record in the table.
Is this the correct understanding regarding primary keys? Assume for this example that there are no NULL values.
Most examples online, do not show a repeated value in a column when creating primary keys such as the first table in which Student_id is repeated several times but each record is a unique record.
appreciate any advice!