Database KEYS

Keys are defined to easily identify any row of data in a table.

  • Key plays a vital role in the relational database (is a collection of data items with pre-defined relationships between them)
  • It is used for identifying unique rows from the table.
  • It also establishes the relationship among tables.
  • A Key can be a single attribute or a group of attributes

Types of Keys

Primary Key – A primary is a column or set of columns in a table that uniquely identifies tuples (rows) in that table.

Super Key – A super key is a set of one or more columns (attributes) to uniquely identify rows in a table.

Candidate Key – A super key with no redundant attribute is known as the candidate key

Alternate Key – Out of all candidate keys, only one gets selected as primary key, remaining keys are known as alternate or secondary keys.

Composite Key – A key that consists of more than one attribute to uniquely identify rows (also known as records & tuples) in a table is called a composite key.

Foreign Key – Foreign keys are the columns of a table that points to the primary key of another table. They act as a cross-reference between tables.

Non-key Attributes

Non-key attributes are the attributes or fields of a table, other than candidate key attributes/fields in a table.


Non-prime Attributes

Non-prime Attributes are attributes other than the Primary Key attribute(s).



Let's take a simple Student table, with fields student_idnamephone and age.

Super Key: 
student_id(student_id, name)phone

Candidate Key: 
student_id and phone

Primary Key: 
student_id

Composite Key: 


No comments:

Post a Comment

Monk and Inversions

using System; public class Solution { public static void Main () { int T = Convert . ToInt32 ( Console . ReadLine...