Superkey, candidate key & primary key

can any kind soul clarify my doubts with a sample example below for the superkey, candidate key and primary key. I know there are alot of posts and websites out there explaining what's the differences between them. But it looks like all are generic definition.

Below shows my following example:

Student (StudentNumber, FamilyName, Degree, Major, Grade, PhoneNumber)

So from the above example, I can know StudentNumber confirm is a primary key.

But as for superkey, i'm abit confused of which are the combination of attributes. Which are the attributes that could be grouped into the superkey?

As for candidate key, i'm confused by the definition given as any candidate key can be qualify as a primary key. Is it meaning that attributes such as phonenumber is a candidate key and can be a primary key? (Assuming that a phonenumber only belongs to one student)

Thanks for any clarification!


Since you don't want textbook definitions, loosely speaking, a super key is a set of columns that uniquely defines a row.

This set can have one or more elements, and there can be more than one super key for a table. You usually do this through functional dependencies.

In your example, I'm assuming:

StudentNumber    unique
FamilyName     not unique
Degree     not unique
Major      not unique
Grade      not unique
PhoneNumber    not unique

In this case, a superkey is any combination that contains the student number.

So the following are superkeys

StudentNumber, FamilyName
StudentNumber, FamilyName, Degree
StudentNumber, FamilyName, Degree, Major
StudentNumber, FamilyName, Degree, Major, Grade
StudentNumber, FamilyName, Degree, Major, Grade, PhoneNumber
StudentNumber, Degree
StudentNumber, Degree, Major
StudentNumber, Degree, Major, Grade
StudentNumber, Degree, Major, Grade, PhoneNumber
StudentNumber, Major
StudentNumber, Major, Grade
StudentNumber, Major, Grade, PhoneNumber
StudentNumber, Grade
StudentNumber, Grade, PhoneNumber
StudentNumber, PhoneNumber

Now assume, if PhoneNumber is unique (who shares phones these days), then the following are also superkeys (in addition to what I've listed above).

PhoneNumber, Grade, 
PhoneNumber, Major, Grade
PhoneNumber, Degree, Major, Grade
PhoneNumber, FamilyName, Degree, Major, Grade
PhoneNumber, Major
PhoneNumber, Degree, Major
PhoneNumber, FamilyName, Degree, Major
PhoneNumber, StudentNumber, FamilyName, Degree, Major
PhoneNumber, Degree
PhoneNumber, FamilyName, Degree
PhoneNumber, StudentNumber, FamilyName, Degree
PhoneNumber, FamilyName
PhoneNumber, StudentNumber, FamilyName

A candidate key is simply the "shortest" superkey. Going back to the 1st list of superkeys (i.e. phone number isn't unique), the shortest superkey is StudentNumber.

The primary key is usually just the candidate key.

Need Your Help

nested dict python keys

python dictionary nested key

I want something like following structure : y['1'][tuple(list)] = val

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.