我在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);
答案 0 :(得分:4)
如果未在references子句中指定列列表,则它将扩展为引用表的主键。
例如:
foreign key(rno) references Receipt
扩展为
foreign key(rno) references Receipt(cid,rno)
因此列数不匹配