建了2个表A B   其中A中有联合主键primary key(a,b)   B中有其他主键  但要将A.a和A.b都作为外键 分成2个外键约束说是不是unique或者PK 无法作为外键 合在一起写:我写的sql是 ALTER TABLE B 
    ADD (CONSTRAINT "a_b_FK" FOREIGN KEY("B.a", "B.b") 
    REFERENCES A("A.a", "A.b")) ;
又说是 parent key not found请问应该怎么写sql?本可以为A新建一个字段作为主键 但题目的要求就是只有a b 两个字段,于是 偶糊涂了多谢各位指点了

解决方案 »

  1.   

    SQL> create table test_a(a int,b int);Table createdSQL> create table test_b (a int,b int);Table createdSQL> alter table test_a add constraint pri_testa primary key (a,b);Table alteredSQL> alter table test_b add(c int);Table alteredSQL> alter table test_b add constraint pri_testb primary key (c);Table alteredSQL> alter table test_b add constraint for_test_b foreign key (a,b) references test_a(a,b);Table altered
      

  2.   

    parent key not found,说明是b表中的a,b取值在A表中不存在。语法是没有问题的