Re: [SQL ] postgresql 複合主鍵無法被外鍵參考?

看板Database作者 (肥兒)時間17年前 (2008/10/30 12:48), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《Bambe (肥兒)》之銘言: : 我建立一個主資料表,有兩個以上的複合主鍵(用 constraint) : 然後在其他的資料表裡,想參考主資料表的某一個主鍵 : 而 psql 卻回我說: : - : 錯誤: number of referencing and referenced columns for foreign key disagree : SQL 狀態: 42830 : - : 英文看不太懂 - -... 所以我去查了狀態碼 : 「42830 非法的外鍵(INVALID FOREIGN KEY) 」 : 這時我把主資料表重建變成一個主鍵 : 就可以被外鍵參考 : 想請問一下為什麼會這樣呢? @@ : 有沒有什麼辦法是可以被外鍵參考呢?謝謝各位大大 :) create table tb_master( "Pkey1" int not null , "Pkey2" int not null, "Pkey3" int not null, constraint pk_pkey primary key ("Pkey1","Pkey2") ); create table tb_slave( "Pkey1" int not null, "Pkey2" int not null, constraint fk_test_pkey1 foreign key ("Pkey1") references tb_master ("Pkey1") ) 有試過pkey不constraint直接 primary key ("Pkey1","Pkey2") 還是一樣無法被 slave 資料表參考... 還有 slave 資料表直接在欄位後面接 reference 也不行QQ 還是一樣一直出現42830的錯誤... Orz -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 192.192.70.253
文章代碼(AID): #192Joic4 (Database)
討論串 (同標題文章)
文章代碼(AID): #192Joic4 (Database)