日期:2014-05-17  浏览次数:20964 次

oracle主外键约束问题,求教!
我在oracle的scott用户下创建了两张表,A表和B表,其中A表的主键是B表的字段,然后我写了添加约束的代码 
alter table B add constraint FK_A_B foreign key (B表与A表约束的字段) references A(A表主键);
然后我直接给B表插入数据(A表没数据),然后成功了,这是为什么呢? 这个问题一般会是什么地方出错了? 
求教!

------解决方案--------------------
官网给的解释:

Issued Against Child Table 子表的约束

OK only if the foreign key value exists in the parent key or is partially or all null

能插入成功,是因为A表为空的关系。
------解决方案--------------------
探讨
官网给的解释:

Issued Against Child Table 子表的约束

OK only if the foreign key value exists in the parent key or is partially or all null

能插入成功,是因为A表为空的关系。

------解决方案--------------------
外键字段设置成 not null了吗。