简体   繁体   中英

Creating a relationship between a composite key and foreign key

I'm trying to link a foreign key to a composite key in mysql but im getting an error saying that the structure of the keys arent correct. I've checked the datatype and character length and both are correct.

Is this link even possible? see below for image...

Composite Key: 在此处输入图片说明

Foreign Key: 在此处输入图片说明

Any help on this would be greatly appreciated.

Not possible to create foreign key from composite key. Should be refer from parent key is primary key and should be not of column in reference key also..as per your share screen not possible to create this.. If you want to achieve this business let me reply will give suggestion to you..

I had my composite key the wrong way round. I switched the 'UniqueCode' to act as the parent key and managed to link fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM