读书人

oracle主外键约束有关问题求教

发布时间: 2012-02-28 13:06:36 作者: rapoo

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了吗。

读书人网 >oracle

热点推荐