What are keys? Name all the keys used in DBMS.
Answer:
- A key is an attribute or set of attributes that help to identify records in a table.
- To retrieve data from more than one table, we join the tables using keys .
- It also controls and maintains integrity of information stored in the database.
- The various types of keys are:
- Primary key
- Candidate key
- Alternate key
- Foreign key
Example:
Employee_id |
Employee_name |
Dept_id |
Emp_Email |
101 |
Ravi Kumar |
1011 |
|
102 |
Tarun A |
1012 |
|
103 |
Jennifer Davis |
1013 |
|
104 |
Martin Woods |
1013 |
|
105 |
Ron Romy |
1012 |
Dept_id |
Dept_name |
1011 |
Sales |
1021 |
IT |
1031 |
HR |
In table Employee,
- Primary key - Employee_id
- Candidate keys - Employee_id,Emp_Email
- Alternate key - Emp_Email
- Foreign key - Dept_id
In table Department,
- Primary key - Dept_id