![](/img/trans.png)
[英]MySQL error showing while creating table to make a relation with another by using foreign key
[英]Mysql showing error while creating primary key and foreign key relation between two tables despite of using index
我在Mysql中有两个表customer_details
和transaction table
。
我有一个named account_no( primary key in customer_details)
并希望与account_no field(foreign key in transaction table)
。 但是它显示错误,表明Foreign key relation could not be added
。
我尝试在两个列中创建索引,但仍然无法正常工作。
ALTER TABLE transaction
添加索引FK_Transaction_AccountNo_idx
( AccountNo
ASC); ALTER TABLE transaction
添加约束FK_Transaction_AccountNo
FOREIGN KEY( AccountNo
)参考customer_details
( AccountNo
)ON删除NO ACTION上UPDATE NO ACTION;
表和列的排序规则应相等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.