Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume the following three are true. (1) The above two tables already exist in a

ID: 3604014 • Letter: A

Question

Assume the following three are true.

(1) The above two tables already exist in a database with data inserted as shown above.

(2) EmpID and Dname are the primary key of Employee and Department tables, respectively.

(3) There is no foreign key constraint defined to relate these two table. That's why employee E012 can have a dept value 'HR', which does not exist in Department.

Leaving current data alone (i.e., without adding or modifying or removing them out of these two tables), how would you relate Employee with Department by enforcing a foreign key constraint such that referencing a non-existing department will never happen again to any new employees? Write an ALTER TABLE statement to answer this question.

Employee Department EmpID Dept Gender Dname Office R&D; K-71 Sales M-22 Sales F E012 HR E354

Explanation / Answer

ALTER TABLE EMPLOYEE ADD FOREIGN KEY(DEPT) REFERENCES DEPARTMENT(DNAME);

EXPLANATION:- we can alter the table to add a foreign key constraint by using ADD FOREIGN KEY CLAUSE with ALTER TABLE CLAUSE

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote