Chin
Chin

Reputation: 20675

Is primary key also super key and candidate key?

Is the primary key also a super key and a candidate key? Their definitions are lengthy but I wonder if this is true?

Please note that I'm not asking if they are the same term. I'm just asking in one direction, not the other way round.

Upvotes: 3

Views: 18343

Answers (6)

hasnaintahir
hasnaintahir

Reputation: 13

Yes we can simply say that a candiate key is primary key but it must be unique.

Upvotes: 0

Sanketssj5
Sanketssj5

Reputation: 665

A candidate key is the most minimal subset of fields that uniquely identifies a tuple. For example if you have a candidate key on the column "user_id" and "pet_id" you'll never have more than 1 tuple with the same user_id and pet_id and neither user_id nor pet_id individually will work as a unique identifier for the tuple.

A super key is a set of fields that contains a key. Using the above example where the combination of "user_id" and "pet_id" uniquely identifies a tuple if we added "pet_name" (which is not key because we can have multiple pets named "fluffy") it would be a super key. Basically it's like a candidate key without the "minimal subset of fields" constraint.

A primary key is a candidate key that you tell the DB to optimize on. There might be multiple ways of referring to a unique tuple (ie. multiple candidate keys) but you can specify one when you're creating the table that you will use the most frequently.

Upvotes: 0

Kobi
Kobi

Reputation: 138017

According to dry definitions:

Your primary key is a super key by definition - you can not have two rows with the same primary key.
However, the primary key is not a natural constraint of your business, but an artificial constraint in your data store: for example, you could set a person's birthday as the primary key in your table, and never have two people who were born on the same day. That would be silly, but possible. In that case, the primary key of the table is not a super key of the domain.

However, your primary key is not necessarily a candidate key - you can add redundant columns to your primary key.

Upvotes: 2

Tuan
Tuan

Reputation: 514

  • Super Key - is a set of one or more columns that can be used to identify a record uniquely in a table

  • Candidate Key – can be any column or a combination of columns that can qualify as a unique key in database. There can be multiple Candidate Keys in one table. Each Candidate Key can qualify as a Primary Key. You can think of this as the "shortest" super key or minimal super key

  • Primary Key – is a column or a combination of columns that uniquely identify a record. Only one Candidate Key can be Primary Key.

For a Candidate Key to qualify as a Primary Key, it should be unique and non-null.

So, basically a primary key is just one of the candidate keys, which is a just a minimal super key.

Upvotes: 7

adsfdsafdsa
adsfdsafdsa

Reputation: 51

It depends.

The Primary key is the main key the table uses to identify between different elements. It is chosen from the candidate keys.

The candidate keys are all the keys that COULD be the primary key. All the keys that are unique and can be differentiated upon in the table.

The super key is a primary key with additional attributes, this extra information is used to uniquely identify an instance of the entity set.

Upvotes: 0

CloudyMarble
CloudyMarble

Reputation: 37566

Different set of attributes which are able to identify any row in the database is known as super key. And minimal super key is termed as candidate key i.e. among set of super keys one with minimum number of attributes. Primary key could be any key which is able to identify a specific row in database in a unique manner. from this thread

And typing all three keys in google gives about 2,480,000 results

Upvotes: 0

Related Questions