[英]ORA-01735 Primary key and Foreign Key
Alter table residential add constraint pk_restype primary key (customerID) REFERENCES customer(customerID);
更改表住宅添加约束pk_restype主键(客户ID)参考客户(customerID);
I'd like to set primary key constraints on 'residential' table but ORA-01735 error appears indicating "invalid ALTER TABLE option". 我想在“居民”表上设置主键约束,但出现ORA-01735错误,指示“无效的ALTER TABLE选项”。 I've also tried the following to make foreign key relation but it also comes up as the same error code.
我还尝试了以下方法来建立外键关系,但它也以相同的错误代码出现。
Alter table residential add constraint fk_restype foreign key (customerID, customertype) REFERENCES customer(customerID, customertype);
更改表住宅添加约束fk_restype外键(customerID,customertype)参考customer(customerID,customertype);
Your problem is you are creating a primary key as if it is a foreign key. 您的问题是您正在创建主键,就好像它是外键一样。
The proper PK syntax is: 正确的PK语法为:
alter table residential add constraint pk_restype primary key (customerID);
No references clause is allowed in a Primary Key, on a Foreign Key. 外键上的主键中不允许任何引用子句。
The PK says this column customerID
is unique and identifies a unique row in the residential
table. PK表示此列
customerID
是唯一的,并标识了residential
表中的唯一行。 It has nothing to do with referencing another table. 它与引用另一个表无关。
A FK would be: FK为:
alter table tab_child add constraint fk_child FOREIGN key (child_id)
REFERENCES tab_parent(id);
The FK says a column child_id
in table tab_child
refers to and is constrained by the column id
in table tab_parent
FK说表
tab_child
一列child_id
表tab_child
的列id
并tab_parent
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.