I have tried inserting these rows into my database INSERT IN
I have tried inserting these rows into my database
INSERT INTO hourly_emp ( Emp_Id,Hourly_pay) VALUES ( 100,10);
INSERT INTO hourly_emp ( Emp_Id,Hourly_pay) VALUES ( 101,10);
but I keep getting this error
(EMORATAY.FK_EMPLOYEE) violated - parent key not found
The database in question is the following..
CREATE TABLE hourly_emp
(
Emp_Id int NOT NULL,
Hourly_pay int,
PRIMARY KEY (emp_Id),
CONSTRAINT FK_employee FOREIGN KEY (emp_Id) REFERENCES
Employee (emp_Id));
Solution
Answer:
The issue here is that we are trying to insert two records with the emp_ids 100 & 101. Since we have a foreign key on employee table emp_id column, we should have matching records in employee table that have emp_ids 100 & 101. Otherwise because of foriegn key constraint SQLwill not allow to insert the date which is not mapped with parent table employee.
To insert these above insert scripts, you need to have a matching recods in parent table employee with emp_ids 100 and 101. But insert the records in parent table employee and try to insert the records in hourly_emp table with matching emp_ids
