Answer: The FOREIGN KEY Constraint
Find a detailed explanation of how to set up a foreign key in a table.
Solution
The solution is given below:
Press + to interact
/* Modifying the EmpID in the Skills table to be NOT NULL */ALTER TABLE SkillsMODIFY COLUMN EmpID INT NOT NULL;/* Adding the foreign key constraint on EmpID in the Skills table */ALTER TABLE SkillsADD FOREIGN KEY (EmpID) REFERENCES Employees (EmpID);/* Describe the structure of the table */DESC Skills;
Explanation
The explanation of the solution code is given below:
Lines 2–3: The
ALTER TABLE
statement makes changes in the structure of theSkills
table. It modifies theEmpID
column to beNOT NULL
. ANULL
value in this column can lead to orphaned rows, which can cause inconsistency and data integrity issues. ...