EXPLAIN KEYS AND TYPES OF KEYS IN DBMS : -
Key is an attribute or set of attribute which is uniquely identifies to a tupple in rdbms. There are various types of keys : -
1.primary key2.candidate key3.super key4.foreign key1.primary key :-
- Primary key is an attribute or set of attribute which is uniquely identifies to a tupple and also should not null.
- For example, in student table S_ID is a primary key because each S_ID is uniquely identifies to a tupple and S_ID can never null so we can say that S-ID is an primary key.
2.candidate key :-
- Candidate key is an attribute or set of attribute which is uniquely identifies to a tupple and it can either null or not null.
- For example, in student table AADHAR_NO is a candidate key because each AADHAR_NO is uniquely identifies to a tupple and it can be either null or not null so we can say that AADHAR_NO is an candidate key.
3.super key :-\
- A super key is a combination of all possible attributes which can uniquely identify two tupples in a table .
- Super set of any candidate key is known as super key .So we can say that if add any attribute With the candidate key then it becomes a super key .
- For example in student table,if roll_no is a candidate key then
roll_no roll_no name roll_no age roll_no name age These are super keys .
4.foreign key :-
Foreign key is an attribute or set of attribute that takes references to the primary key of same table or another table .
Note :
- foreign keys maintain the referential integrity.
- Integrity means same value in the database.