mysql> create table dispatch(
booking_no int
,bdate date
,src_stn varchar(20)
,dest_stn varchar(20)
,consignee varchar(30)
,desc_goods varchar(40)
,no_of_art smallint
,total float
,driver_name varchar(30)
,lorry_no varchar(10)
,status varchar(5)
,primary key (booking_no)
,foreign key(booking_no,bdate,src_stn,dest_stn,consignee,desc_goods,no_of_art,total) references booking(booking_no,bdate,src_stn,dest_stn,consignee,desc_goods,no_of_art,total));
ERROR 1215(HY000):无法添加外键约束
答案 0 :(得分:-1)
试试这个: -
首先使用主键CONSTRAINT创建两个普通表
然后,
ALTER TABLE dispatch ADD FOREIGN KEY(booking_no)REFERENCES预订(booking_no);