新建了一个表,语句如下:
create table course
(cno char(4) primary key,
cname char(40),
cpno char(4),
ccredit smallint,
foreign key cpno references course(cno)
);插入时语句为:
insert into course values('1','database','5','4')执行时出现了问题:ORA 02291: 违反完整约束条件 (SCOTT.SYS_C005172) 未找到父项关键字这里cpno相对应的参照列是cno,已经赋值了。
我用的是PLSQL Developer
各位大侠帮帮忙
create table course
(cno char(4) primary key,
cname char(40),
cpno char(4),
ccredit smallint,
foreign key cpno references course(cno)
);插入时语句为:
insert into course values('1','database','5','4')执行时出现了问题:ORA 02291: 违反完整约束条件 (SCOTT.SYS_C005172) 未找到父项关键字这里cpno相对应的参照列是cno,已经赋值了。
我用的是PLSQL Developer
各位大侠帮帮忙
ORA-02291: integrity constraint (string.string) violated - parent key not found
Cause: A foreign key value has no matching primary key value.
Action: Delete the foreign key or add a matching primary key.
create table course
(cno char(4) primary key,
cname char(40),
cpno char(4),
ccredit smallint,
foreign key cpno references course(cno)
); 楼主的表设计的有问题呀, 怎么外键也是关连自己呀, 这样你怎么插入呀. 外键是用来关联其他表的,要是不需要关联,不建外键就可以了.
可以这样设计,cpno表示先行课,是外码,被参照表是course,也就是本身,被参照列是cno,只有cno有相对应值的时候cpno才允许插入。
先插入
insert into course values('5','test','5',0);