Can a superkey include things that aren't part of the primary key?
Logically speaking, yes. If table X
has columns {A, B, C}
and A
is the primary key then {A}
, {A, B}
, {A, C}
and {A, B, C}
are all superkeys because if you have any one of those sets, you know all the values in the row (if it exists.)
However it's not treated as a key in SQL for some purposes, e.g. if table Y
has A
and B
you can not usually define a foreign key Y(A, B) REFERENCES X(A, B)
, because {A, B}
is not a primary key. If you want to be able to declare that foreign key you must add another UNIQUE
constraint on X(A, B)
which is inefficient as it duplicates part of the primary key.
In my opinion this is one of the many flaws of SQL.