Hi, I am currently in an Intro to Database class and I am learning the basics of
ID: 3703145 • Letter: H
Question
Hi,
I am currently in an Intro to Database class and I am learning the basics of SQL at the moment. I am currently working on an assignment and I am getting an error for when I am entering values into the data tables. The error is ORA-02291: integrity constraint (SQL_DEIJPYXRBUPSAXYFLBNFLXZED.SYS_C001408692) violated - parent key not found ORA-06512: at "SYS.DBMS_SQL", line 1721 . I am stuck and not sure what to do right now; I have posted the assignment and the code I have so far. I appreciate the help!
Thanks!
Assignment
Code:
CREATE Table store
( storeid VARCHAR (3) NOT NULL,
storezip CHAR (5) NOT NULL,
PRIMARY KEY (storeid));
CREATE Table employee
( employeeid VARCHAR(5) NOT NULL,
employeefname VARCHAR(25) NOT NULL,
employeelname VARCHAR(25) NOT NULL,
storeid VARCHAR(3) NOT NULL,
PRIMARY KEY (employeeid),
FOREIGN KEY (storeid) REFERENCES store(storeid) );
INSERT INTO employee VALUES ('E1234' , 'George', 'Loocas','S1');
INSERT INTO employee VALUES ('E1235', 'Steven', 'Speelberg', 'S2');
Explanation / Answer
Answer)
I understand that you're getting an error for entering values into the data tables in Employee table. There is a violation for the integrity constraint as there is no Store Id present in the Store table for the foreign key storeid in the employee table. So we have to first insert corresponding values in the Store table and then insert values in the Employee table. The code for it is as below:
CREATE Table store
( storeid VARCHAR (3) NOT NULL,
storezip CHAR (5) NOT NULL,
PRIMARY KEY (storeid));
CREATE Table employee
( employeeid VARCHAR(5) NOT NULL,
employeefname VARCHAR(25) NOT NULL,
employeelname VARCHAR(25) NOT NULL,
storeid VARCHAR(3) NOT NULL,
PRIMARY KEY (employeeid),
FOREIGN KEY (storeid) REFERENCES store(storeid) );
insert into store values('S1','78867');
insert into store values('S2','66553');
INSERT INTO employee VALUES ('E1234' , 'George', 'Loocas','S1');
INSERT INTO employee VALUES ('E1235', 'Steven', 'Speelberg', 'S2');
On executing the above script values will be successfully inserted in the Employee Table.
This you can check by the query:
select * from employee;
Output:
employeeid employeefname employeelname storeid
E1234 George Loocas S1
E1235 Steven Speelberg S2
The above is the desired output.
/*Hit Like if you like my answer*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.