0
以下查询已成功完成,但是当我将空值输入到订单标识和项目标识的不同值(列中不存在的那些值)时,订单标识仍为越来越多。如何保留相同的订单ID?外键的使用方式有问题吗?两列主键,自动递增和外键
CREATE TABLE orders(
orderid int not null auto_increment,
itemid int not null,
quantity int not null,
tot_price int not null,
cid int not null,
code varchar(10),
order_time time,
order_date date ,
constraint order_pk primary key (orderid, itemid),
foreign key (itemid) references items(itemid),
foreign key (cid) references customer(cid),
foreign key (code) references coupon(code)
);
您需要更好地标准化。你应该有第三个包含你的订单项目的表格,否则你会在每一行重复很多不必要的值。 –
你正在使用哪种引擎类型? –
作为一个附注,在不同的字段中有order_time和order_date是奇数。单个[DATETIME字段](https://dev.mysql.com/doc/refman/5.6/en/datetime.html)如何?这将使得范围计算变得更简单。索引会使事情变得更快。 – Schwern