Different types of Keys in DBMS

PRASANTH
2 min readSep 17, 2020

Before discussing about different keys, i would like to explain what is a Key in DBMS?

A key is an attribute or set of attributes which helps you to identify a tuple(Row) in a relation(table).

A key help you uniquely identify a row in a table by a combination of one or more columns in that table. They allow you to find the relation between two tables.

Let’s discuss different keys in DBMS.

Primary Key: is a column or group of columns in a table that uniquely identify every row in that table.

EMPNO is a Primary Key

Rule for defining Primary Key:

  1. The primary key field cannot be null
  2. Primary Key can’t be a duplicate, which means same value can’t appear more than once in same primary key column

Note: Primary key created with group of columns is Composite Primary Key

Foreign Key: is a column that creates a relationship between two tables

Create relation between Child Table (T1) and Parent Table (T2) based on on DEPTNO column

Super Key: sets of columns which uniquely identify a Row of a Table.

  1. EMPNO
  2. EMPNO, ENAME
  3. ENAME, HIREDATE
  4. ENAME, HIREDATE, DEPTNO

You can consider these set of attributes are known as Super Keys

Candidate Key: Minimal set of columns which uniquely identify a row in a table.

  1. EMPNO
  2. EMPNO, ENAME

A Candidate Key is subset of Super Key.

A Primary Key is selected from a set of Candidate Keys

also we have Alternate key, Surrogate Key …

Next, We’re going to discuss about “Datatypes in SQL” [ https://medium.com/@pk0411/data-types-in-sql-814faf291517 ]

--

--

PRASANTH
0 Followers

Techie | Investor | Freelancer | Blogger | Vegetarian