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

解决方案 »

  1.   

    官网给的解释:Issued Against Child Table 子表的约束OK only if the foreign key value exists in the parent key or is partially or all null能插入成功,是因为A表为空的关系。
      

  2.   

    外键字段设置成 not null了吗。
      

  3.   

    才刚接触oracle,前两楼的答案没看懂!
      

  4.   


     弄好了,就是没有设置not null的原因!  谢谢!