[英]ORA-01735 Primary key and Foreign Key
更改表住宅添加約束pk_restype主鍵(客戶ID)參考客戶(customerID);
我想在“居民”表上設置主鍵約束,但出現ORA-01735錯誤,指示“無效的ALTER TABLE選項”。 我還嘗試了以下方法來建立外鍵關系,但它也以相同的錯誤代碼出現。
更改表住宅添加約束fk_restype外鍵(customerID,customertype)參考customer(customerID,customertype);
您的問題是您正在創建主鍵,就好像它是外鍵一樣。
正確的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說表tab_child
一列child_id
表tab_child
的列id
並tab_parent
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.