作者Bambe (肥儿)
看板Database
标题Re: [SQL ] postgresql 复合主键无法被外键参考?
时间Thu Oct 30 12:48:43 2008
※ 引述《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