更改表格住宅添加约束pk_restype主键(customerID)REFERENCES customer(customerID);
我想在'住宅'上设置主键约束。表但出现ORA-01735错误表示" ALTER TABLE选项无效"。我还尝试了以下方法来建立外键关系,但它也出现了相同的错误代码。
更改表住宅添加约束fk_restype外键(customerID,customertype)REFERENCES customer(customerID,customertype);
答案 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
列约束