所以我试图创建一个在线比萨订单系统。我的问题是在为送货人创建表时,我应该在送货员表中使用仅 cust_id还是我还应该包含 cust_address
CREATE TABLE CUSTOMER
(
cust_id varchar(7) not null,
cust_name varchar(30) not null,
cust_address varchar(40) not null,
cust_num varchar(11) not null,
order_id int,
primary key(cust_id)
);
CREATE TABLE Delivery_Boy
(
employee_id varchar(7) not null,
cust_id varchar(7) not null,
order_id int,
primary key(employee_id),
foreign key(order_id) references PIZZA_ORDER(order_id),
foreign key (cust_id) REFERENCES Customer(cust_id)
);
答案 0 :(得分:2)
只有cust_id
才能通过使用cust_address
加入两个表来获得cust_id
。
喜欢这个
SELECT DB.cust_id,C.cust_name,C.cust_address,C.cust_num,C.order_id
FROM CUSTOMER C INNER JOIN Delivery_Boy DB
ON C.cust_id = DB.cust_id