[英]How to create a mysql table with multiple foreign keys and multiple columns
所以我已經研究了幾個小時,沒有運氣找到適合我嘗試做的事情。
我目前遇到兩個問題:使用多個外鍵引用同一主鍵創建表,然后將這些屬性拆分為多個列。
最后,我希望表看起來像這樣,其中我的O-Director_ID是一列中的主鍵 ,該主鍵與另一列中的所有其他ID(在本例中為FAD_ID,SAD_ID和SUD_ID)相關與另一個表中的主 鍵相對應的所有外鍵 (來自crew_member的Member_ID,已經存在)。
這是我目前正在嘗試做的,只是創建多個外鍵(我什至不知道如何創建第二列):
mysql> create table Other_Directing (
-> O_Director_ID int (4) not null auto_increment,
-> FAD_ID int (5) not null,
-> SAD_ID int (5) not null,
-> SUD_ID int <5> not null,
-> primary key (O_Director_ID),
-> foreign key (FAD_ID) references crew_member(Member_ID),
-> foreign key (SAD_ID) references crew_member(Member_ID),
-> foreign key (SUD_ID) references crew_member(Member_ID)
-> );
但是,即使這不起作用,我也會收到以下錯誤消息:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'<5> not null,
primary key (O_Director_ID),
foreign key (FAD_ID) references crew_'
at line 5
謝謝,我希望這是有道理的。
問候,
麥可
將SUD_ID int <5> not null,
更改為: SUD_ID int (5) not null,
您的項目是否真的需要在int列上使用非默認大小? 如果是這樣,則您有錯字...您的尺寸之一是用<>而不是()的: -> SUD_ID int <5> not null
應為-> SUD_ID int (5) not null
如果您確定確實由於內存限制而想要大小:
create table Other_Directing (
O_Director_ID int not null auto_increment,
FAD_ID int not null,
SAD_ID int not null,
SUD_ID int not null,
primary key (O_Director_ID),
foreign key (FAD_ID) references crew_member(Member_ID),
foreign key (SAD_ID) references crew_member(Member_ID),
foreign key (SUD_ID) references crew_member(Member_ID)
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.