Super Key, Candidate Key, Primary Key & Foreign Key

Super Key

In the relational data model a Superkey is a set of attributes that uniquely identifies each tuple of a relation.

Example Consider following relation 


A

B

C

D

1

1

2

1

2

3

3

1

3

1

2

3

4

2

6

1


As per the definition In this relation the Super Keys are as follows using this we can uniquely identify the tuples in the relation. ​

{ A, AB, AC, AD, ABCD,BD,CD}​


Candidate Key

A candidate key (or minimal superkey) is a superkey that can't be reduced to a simpler superkey by removing an attribute.

  • Candidate Key is Minimal Super Key​
    • s2 ⊆ s1 and s1 ⊄ s2 where s1 and s2 set of key/super key​
    • s2 is subset of s1 and s1 should not be subset of s2​
  • Example consider the same relation​ 
 

A

B

C

D

1

1

2

1

2

3

3

1

3

1

2

3

4

2

6

1

The Candidate Keys are​  {A, BD, CD}


  • Consider the Super Key with previous example ​
    • S1={ A, AB, AC, AD, ABCD,BD,CD}​
  • The Candidate Key​
    • S2={A, BD, CD}​
  • Check the condition of candidate key ie.,​
    • s2 ⊆ s1 and s1 ⊄ s2 where s1 and s2 set of key/super key​
    • s2 is subset of s1 and s1 should not be subset of s2​
  • The above condition it qualifies the rule of candidate key (minimal Superkey condition satisfies)​

Primary Key

  • Primary Key is minimal super key ​
  • Primary Key is a candidate key​
  • A relation has only one Primary Key out of several candidate key.​

Foreign Key​

  • A foreign key is a set of attributes in a table that refers to the primary key of another table. 
  • The foreign key links two tables.
  • Every employee works in a specific department in a company, and employee and department are two different entities. So we can't store the department's information in the employee table. That's why we link these two tables through the primary key of one table.
  • We add the primary key of the DEPARTMENT table, Department_Id, as a new attribute in the EMPLOYEE table.
  • In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are related.
Composite Key

Whenever a primary key consists of more than one attribute, it is known as a composite key. This key is also known as Concatenated Key.

Artificial key

The key created using arbitrarily assigned data are known as artificial keys. These keys are created when a primary key is large and complex and has no relationship with many other relations. The data values of the artificial keys are usually numbered in a serial order.

Post a Comment

0 Comments