×

DBMS Keys: Primary, Super, Candidate, Foreign

In database management system, keys play an important role which is used for identifying unique records by the combination of one or more fields in the database table. Keys also allows you to establish the relationship between the database tables.

Different types of keys

  1. Primary key
  2. Super key
  3. Candidate key
  4. Foreign key
  5. Alternate key or Secondary key
  6. Composite key

Primary key

A primary key is a field or a set of fields in a database table that uniquely identifies each record in that table. In a table, there can be more than one candidate key from which one of the key is selected as a primary key.

  • The value of the primary key field cannot be NULL.
  • A table is allowed to have only one primary key.
  • The value of a primary key field should always be unique.

Example:

In the Student table, Student_id can be a primary key since it is unique for each student. In the Student table, we can even select Aadhar_Number as a primary key as it is also unique.

Table: Student

Student_id Name Department_id Aadhar_Number

Primary key

Super Key

A super key is a set of single and multiple key attributes which is used to identify records in a table. The super key is a superset of the candidate key.
The set of all attributes or fields to identify the tuples in a relation is called the trivial super key.

Example:

Table Student:

Student_id Name Department_id


Following are the examples of a super key for the table Student:

1. Student_id
2. (Student_id, Name)
3. (Name, Department_id)

Candidate key

A minimal (minimum) set of attributes that can uniquely identify each record in a relation is called a candidate key. It is a subset of a super key.

  • The value of the candidate key field must be unique and always be not NULL for every tuple.
  • There can be more than one candidate key in a table or a relation.
  • Removing any field from the candidate key fails in identifying each record uniquely.

Example:

Table student:

Student_id Name Department_id

Following are the examples of candidate key for above table:

1. Student_id
2. (Student_id, Name)

Foreign key

A foreign key is anattribute in one table that acts as a primary key in another table. The foreign key is useful for establishing the relationship between two tables in a database.

Example:

In a college, every student study in a specific department, and department and student are two different entities. So you cannot store the information of the student in the department table. That's why we relate these two tables using the primary key of one table.

Example:
We create the primary key on the field department_idof the DEPARTMENT table.
Now in the student table, Department_id is the foreign key, and both the tables are linked.

Alternate key

Those keys which are not selected as the primary key from the candidate keys are called as the alternate keys. These keys are also known as the secondary keys.

Example:
Table student:

Student_id Name Department_id

The example of candidate key for above table:(Student_id, Name)

Composite key

A composite key is a key which is a combination of two or more fields (attributes) that uniquely identify each record in the table.

Example:

Table student:

Student_id Name Department_id


The examples of the composite key for above table: (Name, Department_id)


Related Topics

Meta Data in DBMS

Metadata: Metadata is simply described as information about information. It indicates that the data is described as well as its context. It makes data easier to find, interpret, and organize. I'll...

4 minutes read.

What is a Database

A database is a structured collection of data that is often kept electronically on a computer system. Typically, a database is managed by a database management system (DBMS). Together, the...

9 minutes read.

Candidate Key in DBMS

Candidate key in DBMS: The candidate key is a single column or the set of columns that uniquely identifies the rows of data in the database table. It is a...

2 minutes read.

Red-Black Tree Deletion in DBMS

Introduction To Red Black Tree Each node's extra bit in a red-black tree, a type of self-balancing binary search tree, is frequently understood as the color (red or black). The balance...

3 minutes read.

What is RDBMS?

To discuss the Relational Database Management System, there are some terms and concepts you need to know. Database Any collection of related information is called a database. The phone book is...

5 minutes read.

How to draw ER-Diagram in DBMS?

Entity Relationship Diagrams, or ERDs, are diagrams that assist you in visualizing your database design. An ERD, also called anER diagram or ER model,describes data and how parts of the data interact. ERDs are crucial in database architecture and projects that call for...

9 minutes read.

What is Transaction in DBMS

A transaction is a collection of logically related operations which reads and possibly updates the various data items in the database. Usually, a transaction is initiated by a user program written in high-level...

3 minutes read.

DBMS Architecture

This is the first step when creating a database management system. The architecture of a database management system plays an important role in determining the actual design and layout of...

4 minutes read.

Advantages of Threaded Binary Tree in DBMS

We know that every node in a binary tree contains both its data value and the address pointers for its left and right children. A null pointer is used to...

3 minutes read.

Data Models in DBMS

Data Models in DBMS Data models are the models explaining the logical structure of the database systems. They describe the entities, attributes, and the relationship among the data elements of the...

8 minutes read.

Entity and Entity set in DBMS

What is DBMS? A database management system (DBMS) is a software application that interacts with end-users, other applications, and the database itself to capture and analyze the data. A DBMS allows...

3 minutes read.

Primary Key in DBMS

Primary Key in DBMS: A primary key is the minimal set of columns in the database table, which uniquely identifies each row or tuple in that table. Any table in...

2 minutes read.

ER Diagram of Company Database in DBMS

Entity Relationship Diagram Entity Relationship Diagrams, or ER Diagrams for short, are diagrams that show the relationships among entity sets that are stored in databases. Alternatively said, ER diagrams assist in...

3 minutes read.

Codds Rule of DBMS

Codd’s Rule of DBMS Database having certain constraints and tables, need not to be a relational database system always. For perfect database management system, there are certain rules for the database,...

3 minutes read.

ER Diagram for School Management System in DBMS

What is ER Diagram? An ERD, or entity relationship diagram, is a diagram that depicts the connections between a group of entities contained in a database. In other words, ER diagrams...

6 minutes read.

DBMS Schema

Schema It is a physical representation of data that appears in the database management system. In simple words, a schema is the structure of any database.It defines how the data is stored...

2 minutes read.

DBMS Architecture

Architecture of Database Management System DBMS architecture helps in development, implementation, design, and maintenance of a database that store and organize information for agencies, businesses, and institutions. It is the base of any database...

2 minutes read.

Normalization in DBMS: 1NF, 2NF, 3NF, BCNF & 4NF with Examples

Normalization is a technique of organizing the data in the database. It is a systematic approach which is used to remove or reduce data redundancy in the tables and remove the...

7 minutes read.

Redundancy in DBMS

Data redundancy is a situation that is created in the database in which the same amount of data is stored in two different places. The different places are found in a...

3 minutes read.

Three Schema Architecture of DBMS

The three schema architecture describes how the data is represented or viewed by the user in the database. This architecture is also known as three-level architecture and is sometimes called...

3 minutes read.