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


defination of superkey , primary key in wikipedia

a superkey set of attributes within table values can used uniquely identify tuple. 

and

the primary key has consist of characteristics cannot duplicated other row. primary key may consist of single attribute or multiple attributes in combination. 

i've gone through many books , surfed on internet found in them

what primarykey , superkey 

but want know why superkey required when can identify tuple uniquely through primarykey ?

thanks in advance.

let's define these terms mean in first place:

  • a "superkey" set of attributes that, when taken together, uniquely identify rows in table.
  • a minimal1 superkey called "candidate key", or "key".
  • all keys in same table logically equivalent, historical , practical reasons choose 1 of them , call "primary", while remaining "alternate" keys.

so, every primary key key, not every key primary. every key superkey, not every superkey key.

constraints physically enforce keys in database are: primary key constraint (for primary key) , unique constraint (for alternate key). these constraints should not created on superkeys, on keys.

it not unusual have multiple keys in same table, depending on nature of data. example, user table might have unique user_id and unique user_name. since both of them need unique on own, must create2 both keys, though 1 of them strictly needed identification.


1 is, superkey stop being unique (and therefore, being superkey) if of attributes removed it.

2 i.e. create primary key or unique constraint.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -