修改表住宅添加约束pk_restype主键(customerID)引用客户(CustomerID);
我想对‘住宅’表设置主键约束,但是出现ORA-01735错误指示“无效的ALTER选项”。我还尝试了以下方法来建立外键关系,但它也是相同的错误代码。
修改表住宅添加约束fk_restype外键(customerID,customertype)引用客户(customerID,customertype);
发布于 2014-10-18 00:45:49
您的问题是,您正在创建一个主键,就好像它是外键一样。
正确的PK语法是:
alter table residential add constraint pk_restype primary key (customerID);
在外键上的主键中不允许引用子句。
PK说这个列customerID
是唯一的,并且标识了residential
表中唯一的行。它与引用另一个表无关。
A FK将是:
alter table tab_child add constraint fk_child FOREIGN key (child_id)
REFERENCES tab_parent(id);
FK表示表child_id
中的列tab_child
引用表tab_parent
中的列id
并受其约束。
https://stackoverflow.com/questions/26435246
复制相似问题