Skip to main content

Difference between Super, Candidate, Primary & Unique keys.

 Difference between Super Key and Candidate Key

Last Updated: 23-02-2021

Super Key:
Super Key is an attribute (or set of attributes) that is used to uniquely
identifies all attributes in a relation. All super keys can’t be candidate keys but its reverse is true. In relation, the number of super keys is more than the number of candidate keys.
Example:
We have a given relation R(A, B, C, D, E, F) and we shall check for being super keys by following given dependencies:

Functional  dependencies                Super key
AB->CDEF                                      YES
CD->ABEF                                      YES
CB->DF                                            NO
D-.BC                                                NO

By Using key AB we can identify the rest of the attributes (CDEF)of the table. Similarly Key CD. But, by using key CB we can only identify D and F, not A and E. Similarly key D.

Candidate Key:
Candidate key is a set of attributes (or attribute) which uniquely identify the tuples in a relation or table. As we know that Primary key is a minimal super key, so there is one and only one primary key in any relation but there is more than one candidate key can take place. Candidate key’s attributes can contain a NULL value which opposes to the primary key.
Example:
Student{ID, First_name, Last_name, Age, Sex, Phone_no}
Here we can see the two candidate keys ID and {First_name, Last_name, DOB, Phone_no}. So here, there are present more than one candidate keys, which can uniquely identify a tuple in a relation.

Difference between Primary key and Unique key

Primary key
A primary key is a column of a table that uniquely identifies each tuple (row) in that table. The primary key enforces integrity constraints to the table. Only one primary key is allowed to use in a table. The primary key does not accept the any duplicate and NULL values. The primary key value in a table changes very rarely so it is chosen with care where the changes can occur in a seldom manner. A primary key of one table can be referenced by foreign key of another table.
For a better understanding of the primary key, we take a table named as Student table, having attributes such as Roll_number, Name, Batch, Phone_number, Citizen_ID.
The roll number attribute can never have identical and NULL value because every student enrolled in a university can have a unique Roll_number, therefore two students cannot have the same Roll_number and each row in a table is uniquely identified with the student’s roll number. So, we can makeRoll_number attribute as a primary key in this case.

Unique key
Unique key constraints also identify an individual tuple uniquely in relation or table. A table can have more than one unique key, unlike a primary key. Unique key constraints can accept only one NULL value for the column.
Unique constraints are also referenced by the foreign key of another table. It can be used when someone wants to enforce unique constraints on a column and a group of columns which is not a primary key.

Comments

Popular posts from this blog

This program checks whether a number is a Special Number or not in JAVA

  This program checks whether a number is a Special Number or not. A number is said to be a special number when the sum of the factorial of its digits is equal to the number itself. Example - 145 is a Special Number as 1!+4!+5!=145. Program- /*import java.util.*; public class SpecialNumberCheck {      public static void main(String args[])      {           Scanner ob=new Scanner(System.in);           System.out.println("Enter the number to be checked.");           int a=ob.nextInt();           int sum=0,b=a;           while(a!=0)//or a>0           {                int rem=a%10; int fact=1;                for(int i=1;i<=rem;i++)      ...

Difference between Primary Key , Foreign Key & Candidate Key

 Last Updated: 23-02-2021 Primary Key: A primary key is used to ensure data in the specific column is unique. It is a column that cannot have NULL values. It is either an existing table column or a column that is specifically generated by the database according to a defined sequence. Example: Refer to the figure – STUD_NO, as well as STUD_PHONE both, are candidate keys for relation STUDENT but STUD_NO can be chosen as the primary key (only one out of many candidate keys). Foreign Key: A foreign key is a column or group of columns in a relational database table that provides a link between data in two tables. It is a column (or columns) that references a column (most often the primary key) of another table. Example: Refer to the figure – STUD_NO in STUDENT_COURSE is a foreign key to STUD_NO in STUDENT relation. Figure: Let’s see the difference between Primary Key and Foreign Key: PRIMARY KEY A primary key is used to ensure data in the specific column is unique. It uniquely identifie...

Python Methods with Description.

Python includes following list methods  1) list.append(obj) = Appends object obj to list  2) list.count(obj) = Returns count of how many times obj occurs in list  3) list.extend(seq) = Appends the contents of seq to list 4) list.index(obj) = Returns the lowest index in list that obj appears 5) list.insert(index, obj) = Inserts object obj into list at offset index 6) list.pop(obj=list[-1]) = Removes and returns last object or obj from list 7) list.remove(obj) = Removes object obj from list 8) list.reverse() = Reverses objects of list in place 9) list.sort([func]) = Sorts objects of list, use compare func if given Function with Description 1) cmp(tuple1, tuple2) = Compares elements of both tuples. 2) len(tuple) = Gives the total length of the tuple. 3) max(tuple) = Returns item from the tuple with max value. 4) min(tuple) = Returns item from the tuple with min value. 5) tuple(seq) = Converts a list into tuple. Built-in Dictionary Functions & Methods Python includes ...