在创建表时尝试创建两个外键时,我收到了这些错误:
1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在第8行的“参考客户customerid,外键产品参考产品prodc”附近使用正确的语法
我的查询:
create table orders(
orderid varchar(10) primary key,
productid varchar(10) ,
customerid varchar(10) ,
dateoforder date,
dateofdelivery date,
paid decimal(12,2),
foreign key customerid references customer (customerid),
foreign key productid references product (prodcode)
);
答案 0 :(得分:1)
应该是:
create table orders(
orderid varchar(10) primary key,
productid varchar(10) ,
customerid varchar(10) ,
dateoforder date,
dateofdelivery date,
paid decimal(12,2),
foreign key (customerid) references customer (customerid),
foreign key (productid) references product (prodcode)
);