Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why superkey is required when we can identify a tuple uniquely through primary key?

Defination of Superkey and Primary key in wikipedia

A superkey is a set of attributes within a table whose values can be used to uniquely identify a tuple.

and

The primary key has to consist of characteristics that cannot be duplicated by any other row. The primary key may consist of a single attribute or a multiple attributes in combination.

I've gone through many books and surfed on internet but what i found in them is what is primarykey and what is superkey.

But what i want to know is why superkey is required when we can identify a tuple uniquely through primarykey ?

like image 635
Praveen Dabral Avatar asked Oct 26 '25 01:10

Praveen Dabral


2 Answers

Let's define what these terms mean in the first place:

  • A "superkey" is any set of attributes that, when taken together, uniquely identify rows in the table.
  • A minimal1 superkey is called "candidate key", or just "key".
  • All keys in the same table are logically equivalent, but for historical and practical reasons we choose one of them and call it "primary", while the remaining are "alternate" keys.

So, every primary key is key, but not every key is primary. Every key is superkey, but not every superkey is key.

Constraints that physically enforce keys in the database are: PRIMARY KEY constraint (for primary key) and UNIQUE constraint (for alternate key). These constraints should not be created on all superkeys, only on keys.

It is not unusual to have multiple keys in the same table, depending on the nature of your data. For example, a USER table might have unique USER_ID and unique USER_NAME. Since both of them need to be unique on their own, you must create2 both keys, even though only one of them is strictly needed for identification.


1 That is, a superkey that would stop being unique (and therefore, being a superkey) if any of the attributes were removed from it.

2 I.e. create PRIMARY KEY or UNIQUE constraint.

like image 156
Branko Dimitrijevic Avatar answered Oct 28 '25 03:10

Branko Dimitrijevic


Superkeys are defined for conceptual completeness. You never need a superkey for reference purposes. A reference to a primary key will do just fine.

The concept of superkeys can be useful when you are analyzing a body of data in order to discover all the functional dependencies in it.

Once you have discovered a key, the next question is whether or not it is a superkey. If is is, you turn your attention to the candidate key contained in the superkey.

like image 37
Walter Mitty Avatar answered Oct 28 '25 04:10

Walter Mitty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!