Keys in DBMS
Keys in DBMS
===========
What is a Key:
==========
-> Key is an attribute or set of attrribute that can be used to determine row of
data in the table uniquely.
ex: consider the following relation student having attributes as
student (sid,sname,sbranch,smarks,smail,sphno)
-> From the above table sid, sphno,smail are consider as key.
Types of Keys:
===========
1) Super Key
2) Candidate Key
3) Primary Key
4) Alternative Key
5) Foreign Key
6) Composit/Compound Primary key
Super Key:
========
-> Super Key is an attribute or set of attrribute that can be used to determine row
of data in the table uniquely.
Candidate Key:
===========
-> Candidate Key is a minimal set of super key that helps you to identify rows of a
data in a table uniquely.
-> If any Proper subset of super key is a candidate key then that key is not a
super key
Alternative key:
===========
-> Alternative key is an attribute or set of attributes that are availble in super
key but not in candidate key
Example:
======
super key : {sid,sphno,smail}
candidate key : {sid,smail}
Alternative key : sphno
Primary Key:
=========
-> Primary key is an attribute that does't allows duplication values and NULL
values while entering the values under the primary key attribute.
-> A Table must and should have only one primary key attribute inorder to identify
records uniquely.
Example : Student(sid,sname,smarks,sphno,smail)
Primary key is : sid
Foriegn Key:
=========
-> Foriegn key is an attrinbute that establish relationship between two tables
-> Foriegn key is an attribute that allows you to enter the values those that are
present in primary key attribute of another table.
example
======
Emp(empid,empname,empsal,empadd,empphno) empid - primary key
dept
===
empid deptno deptname deptloc
111 10 civil ff
111 20 mech sf -> allows
333 30 EEE tf -> won't allowed (since parent key is
not found)