ORA-01735主键和外键

时间:2014-10-18 00:43:28

标签: foreign-keys primary-key ora-01735

  

更改表格住宅添加约束pk_restype主键(customerID)REFERENCES customer(customerID);

我想在'住宅'上设置主键约束。表但出现ORA-01735错误表示" ALTER TABLE选项无效"。我还尝试了以下方法来建立外键关系,但它也出现了相同的错误代码。

  

更改表住宅添加约束fk_restype外键(customerID,customertype)REFERENCES customer(customerID,customertype);

1 个答案:

答案 0 :(得分:0)

您的问题是您正在创建主键,就像它是外键一样。

正确的PK语法是:

alter table residential add constraint pk_restype primary key (customerID);

外键上的主键中不允许使用引用子句。

PK说这个列customerID是唯一的,它标识residential表中的唯一行。它与引用另一个表无关。

FK将是:

alter table tab_child add constraint fk_child FOREIGN key (child_id)
   REFERENCES tab_parent(id);

FK表示表child_id中的列tab_child引用并受表id中的tab_parent列约束

相关问题