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.
Rule for defining Primary Key:
- The primary key field cannot be null
- 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
Super Key: sets of columns which uniquely identify a Row of a Table.
- EMPNO
- EMPNO, ENAME
- ENAME, HIREDATE
- 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.
- EMPNO
- 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 ]