ORA-02291:违反了完整性约束 - 未找到父密钥

时间:2015-12-07 18:27:04

标签: oracle

这是我的数据库:

CREATE TABLE courses ( 
ccode     VARCHAR2(10)  CONSTRAINT courses_PK  PRIMARY KEY, 
cname     VARCHAR2(50), 
coursefee NUMBER(6)
);

CREATE TABLE faculty (
fcode     VARCHAR2(5)  CONSTRAINT faculty_PK PRIMARY KEY,
name      VARCHAR2(50)
);

CREATE TABLE batches (
bcode varchar2(5) CONSTRAINT batches_PK PRIMARY KEY,   
ccode varchar2(5) CONSTRAINT batches_ccode_FK  REFERENCES COURSES(ccode),  
fcode varchar2(5) CONSTRAINT batches_fcode_FK  REFERENCES FACULTY(fcode),   
stdate date CONSTRAINT batches_stdate_nn not null,  
enddate date,  
timing number(1) CONSTRAINT batches_timing_chk  check( timing in (1,2,3) ),   
CONSTRAINT batches_date_chk check ( stdate <= enddate) 
);   

CREATE TABLE students (
rollno number(5) CONSTRAINT students_PK PRIMARY KEY,   
bcode varchar2(5) CONSTRAINT students_bcode_FK REFERENCES batches(bcode),   
name varchar2(30),
gender char(1) CONSTRAINT students_gender_chk check( upper(gender) in ('M','F')),   
dj date,   
phone varchar2(10),   
email varchar2(30) 
); 

插入表格:

INSERT INTO batches VALUES('A0001','A0016','A0031','08-05-13','08-06-17',1); 
INSERT INTO batches VALUES('B0002','E0017','B0032','08-05-13','08-06-26',2); 
INSERT INTO batches VALUES('C0003','C0018','C0033','08-06-27','08-06-28',2); 
INSERT INTO batches VALUES('D0004','D0019','D0034','08-06-27','08-08-11',3);
INSERT INTO batches VALUES('E0005','E0020','E0035','08-07-01','08-08-09',2); 
INSERT INTO batches VALUES('F0006','F0021','F0036','08-07-21','08-08-11',1);
INSERT INTO batches VALUES('G0007','V0022','G0037','08-08-31','08-09-21',3); 
INSERT INTO batches VALUES('H0008','H0023','H0038','08-09-17','08-10-14',3);
INSERT INTO batches VALUES('I0009','I0024','I0039','08-09-23','08-10-20',2); 
INSERT INTO batches VALUES('J0010','P0025','J0040','08-10-04','08-11-26',1);
INSERT INTO batches VALUES('K0011','F0026','K0041','08-10-10','08-11-17',2); 
INSERT INTO batches VALUES('L0012','C0027','L0042','08-11-02','09-02-23',2);
INSERT INTO batches VALUES('M0013','M0028','M0043','08-12-09','09-01-02',3); 
INSERT INTO batches VALUES('N0014','N0029','N0044','08-12-11','09-01-08',3);
INSERT INTO batches VALUES('O0015','O0030','O0045','08-12-15','09-01-12',2); 

INSERT INTO students VALUES(001,'A0001','Andrew Johnson','M','08-01-10','677-0323','AndyJ@hotmail.com');
INSERT INTO students VALUES(002,'B0002','Dionne Peterson','F','08-01-10','324-9705','dionnepet@gmail.com');
INSERT INTO students VALUES(003,'C0003','Sydney Peters','F','08-01-10','624-9664','SydersP@yahoo.com');
INSERT INTO students VALUES(004,'D0004','Tsian Figaro','F','08-09-01','310-4957','tsianfigaro@hotmail.com');
INSERT INTO students VALUES(005,'E0005','Jewel Forbes','F','08-09-01','666-5948','Jewel@gmail.com');
INSERT INTO students VALUES(006,'F0006','Jason Fitzpatrick','M','08-01-02','657-4958','JasonFitz@hotmail.com');
INSERT INTO students VALUES(007,'G0007','Ali Maharaj','M','08-01-02','674-4437','AliMaharaj@gmail.com');
INSERT INTO students VALUES(008,'H0008','Mariah Sunderstone','F','08-01-02','707-4056','mariahS@yahoo.com');
INSERT INTO students VALUES(009,'I0009','Ariah Baron','F','08-01-02','673-9685','AriBar@yahoo.com');
INSERT INTO students VALUES(010,'J0010','Joe Zheng ','M','08-09-01','348-4567','Zhengdo@hotmail.com');
INSERT INTO students VALUES(011,'K0011','Donald Yen','M','08-09-01','328-4749','DonnieYen@gmail.com');
INSERT INTO students VALUES(012,'L0012','Jackson Chang','M','08-08-27','345-6847','JackieChang@yahoo.com');
INSERT INTO students VALUES(013,'M0013','Scott Smith','M','08-01-02','702-9903','Scottsmith@hotmail.com');
INSERT INTO students VALUES(014,'N0014','Michelle Shareef','F','08-02-27','321-0589','michelleShareef@gmail.com');
INSERT INTO students VALUES(015,'O0015','Jean Louis Pierre ','M','08-09-01','428-8378','JLPierre@gmail.com');

批次持续出现的错误表是: ORA-02290:违反检查约束(EJAY.BATCHES_DATE_CHK)

为学生提供的错误表是: ORA-02291:违反了完整性约束 - 未找到父密钥

我感到困惑的是它只显示表格中的某些行。教师和课程都很好,就是这两个。 如果答案很明显,我道歉,我是初学者。请帮忙

1 个答案:

答案 0 :(得分:1)

插入批次失败是因为你的日期已经混淆了;他们是dd-mm-yy。 例如,<div class="" ng-repeat="selectedCard in Cards | filter: filterValueStatus == '2' ? {status:'2'} : {status:'3', monitorLevel:filterValueLevel, monitorSystem:filterValue}"> 未通过测试INSERT INTO batches VALUES('D0004','D0019','D0034','08-06-27','08-08-11',3);

学生中的插入失败是因为您指的是不存在的批次中的值(因为插入失败了吗?)。