CREATE TABLE Products
(
pid INT NOT NULL,
pname varchar(50) NOT NULL,
price INT NOT NULL,
stock INT NOT NULL,
PRIMARY KEY (pid)
);
CREATE TABLE Customer
(
Cid INT NOT NULL,
Cname varchar(50) NOT NULL,
Caddress varchar(150) NOT NULL,
Ccontact varchar(20) NOT NULL,
PRIMARY KEY (Cid),
);
CREATE TABLE orders
(
orderid int not null,
quantity int not null,
purchased_on date not null,
totalprice float not null,
Cid INT NOT NULL,
Pid INT NOT NULL,
PRIMARY KEY (orderid),
FOREIGN KEY (pid) REFERENCES Products(pid)
FOREIGN KEY (cid) REFERENCES Customers(pid)
);
为什么代码无法运行pgadmin III,
感谢。
答案 0 :(得分:0)
所有脚本应更正如下。阅读更正前面的注释。所有大写的列名和表名都放在双引号内。
CREATE TABLE "Products"
(
pid INT NOT NULL,
pname varchar(50) NOT NULL,
price INT NOT NULL,
stock INT NOT NULL,
PRIMARY KEY (pid)
);
CREATE TABLE "Customer"
(
"Cid" INT NOT NULL,
"Cname" varchar(50) NOT NULL,
"Caddress" varchar(150) NOT NULL,
"Ccontact" varchar(20) NOT NULL,
PRIMARY KEY ("Cid") -- Removed additional comma (,)
CREATE TABLE orders
(
orderid int not null,
quantity int not null,
purchased_on date not null,
totalprice float not null,
"Cid" INT NOT NULL,
"Pid" INT NOT NULL,
PRIMARY KEY (orderid),
FOREIGN KEY ("Pid") REFERENCES "Products"(pid), -- Added missing comma (,)
FOREIGN KEY ("Cid") REFERENCES "Customer"("Cid") -- Referenced table should be Customer not Customers and reference key should be Cid not pid
);