簡體   English   中英

ORA-01735主鍵和外鍵

[英]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_idtab_child的列idtab_parent

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM