KEYS IN RDBMS (PRIMARY KEY, SUPER KEY, CANDIDATE KEY)


KEYS IN RDBMS (Data Constraints)

Many keys are available in the RDBMS, They allow finding the relation between columns and table that help identify a tuple (row) in a table. They help find a unique record from the table or database.  

 Keys are seven types in RDBMS

  1. Primary key
  2. Super key
  3. Alternate key
  4. Foreign key
  5. Candidate key
  6. Unique key
  7. Composite key

                                                                   Fig 1.2 KEYS

1.      PRIMARY KEY

A primary key is an attribute (columns) of a table or group of columns that uniquely identify each record in a table. This contains a unique value that’s no repetition for any row. It cannot be a null value. A table contains only one primary key. Example:-

Roll_no

Name

class

Father name

1

Rohit

MCA

Sohan pal

2

Priya

MCA

Jitendra

3

Ritika

MCA

Bhanu Singh

4

Vishal

MCA

Pritam Singh

 COLLEGE OF ENGINEERING ROORKEE

In the above example, Roll_no is the primary key.

Some rules for primary key:

·         Modification of the primary key is not allowed.

·         Primary the key attribute cannot be null.

·         Always uniquely identify or no repetition.

 

2.      SUPER KEY/ CANDIDATE KEY  

It is collection of one or more attribute (columns) which help identify a row in a table. Some person gets are confused between super key and candidate key.

A candidate key is the sub-set of the super key. A minimal set of attributes can be used to identify a single row in a table. Example:-

Table: Student

Roll_no

Name

Mob

1

Meenal

9844722

2

Sheetal

2696102

3

Abhay

5641566

4

Vishal

2585144

   In the above table, list out all the sets of attributes

  • { }
  • {Roll_no}
  • {name}
  • {mob}
  • {roll_no, name}
  • {roll_no, mob}
  • {name, mob}
  • {Roll_no, name, mob}

Candidate key, An set of attributes that can uniquely identify the row of a table. In the above example Roll_no, Name, Mob are the candidate key.

Some of the rule for candidate key:

·         Uniquely identify each row (tuple) in a table.

·         It should contain the minimum attribute to ensure uniqueness.

·         In a table, one or more candidate keys. 

      

Comments