Q38.Marks: +2.0UGC NET Paper 2: Computer Science 11 March 2023
Consider the two relations below. The primary keys are underlined. Identify all possible foreign key(s) from the options based only on the two relations.
EMP (eid, ename, did)
DEPT (did, dname)
1.eid
2.did✓ Correct
3.eid, did
4.eid, did, ename
Solution
The correct answer is did
Key Points
Foreign Key: A foreign key in a database is a field or collection of fields in one table, that is a primary key in another, related table. The purpose of the foreign key is to ensure referential integrity of the data.
In the relation provided, 'did' in the EMP relation can be a foreign key that refers to the 'did' in the DEPT relation. The column 'did' in the EMP relation identifies the department to which an employee belongs, and it's reasonable to think that each 'did' in EMP corresponds to a 'did' in DEPT.
Additional Information
Primary Key: The primary key is a distinct type of candidate key chosen by the database designer to make a row unique in a table. It can neither have null values nor duplicate values.
Super Key: A super key is a set, or any subset of, one or more columns (attributes) that can be used to uniquely identify a record in a database table. It can include extraneous attributes.
Candidate Key: A candidate key is a minimal set of columns (that is, a super key reduced to its irreducible minimum) which can uniquely identify a record. There can be more than one candidate key, but they each must be able to uniquely identify a record without any extraneous data.