gpt4 book ai didi

sql - 在 PostgreSql 中获取 "number of referencing and referenced columns for foreign key disagree"

转载 作者:行者123 更新时间:2023-11-29 11:58:46 27 4
gpt4 key购买 nike

我在 pgAdmin 4 中创建了一些表,但由于某种原因我一直收到标题错误,你能找出原因吗?我没有看到任何问题,并且我已经查看了与我的代码示例相似的其他代码示例,这些示例编译得很好。它在 IDEone ( http://ideone.com/ZBn2Nr ) 中也运行正常。

谢谢!

Create table item
(iname varchar(30) primary key,
itype varchar(30));

Create table Cafe
(license numeric(5,0) primary key,
cname varchar(30),
address varchar(30));

Create table Client
(cid numeric(5,0) primary key,
name varchar(30),
phone numeric(9,0));

Create table Likes
(cid numeric(5,0),
iname varchar(30),
primary key(cid,iname),
foreign key(cid) references Client,
foreign key(iname) references item);

Create table Sells
(license numeric(5,0),
iname varchar(30),
price float check(price > 0),
primary key(license,iname),
foreign key(license) references Cafe,
foreign key(iname) references item);

Create table Receipt
(cid numeric(5,0),
rno numeric(5,0),
license numeric(5,0),
rdate date,
primary key(cid,rno),
foreign key(cid) references Client,
foreign key(license) references Cafe);

Create table Buys
(cid numeric(5,0),
rno numeric(5,0),
iname varchar(30),
amount int check(amount > 0),
primary key(cid,rno,iname),
foreign key(cid) references Client,
foreign key(rno) references Receipt,
foreign key(iname) references item);

最佳答案

当您未在引用子句中指定列列表时,它将扩展为引用表的主键。

例如:

foreign key(rno) references Receipt

扩展为

foreign key(rno) references Receipt(cid,rno)

所以列数不​​匹配

关于sql - 在 PostgreSql 中获取 "number of referencing and referenced columns for foreign key disagree",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45346269/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com