0

私は大学でMYSQLを学び始めたばかりで、クラ​​スのために行うべき重要な任務があります。小さなデータベースを作成する必要がありますが、errno(150)が原因で、外部キーを含むテーブルを追加できないようです。これが私が持っているものです。

create table Country
(CountryName varchar (50) not null,
Primary Key (CountryName));

create table InterestGroup
(IntrestgrpName varchar (30) not null,
Primary Key (IntrestgrpName));

create table Organisation
(OrgName varchar (50) not null,
OrgAddress varchar (30),
OrgTelNo.varchar (30),
Primary Key (OrgName));

create table Qualification
(QualName varchar (50) not null,
Primary Key (QualName));

create table Member
(MemberID varchar (15) not null,
MemberName varchar (30),
MemberAdd varchar (50) not null,
CountryName varchar (50) not null,
IntrestgrpName varchar (30) not null,
QualName varchar (50) not null,
OrgName varchar (50) not null,
Primary Key (MemberID),
Foreign Key (CountryName) References Country (CountryName),
Foreign Key (IntrestgrpName) References InterestGroup (InterestgrpName),
Foreign Key (QualName) References Qualification (Qualname),
Foreign Key (OrgName) References Organisation (OrgName));

メンバーテーブルを作成できないようです。このエラーが発生します。エラー1005(HY000):テーブル'iicp.member'を作成できません(errno:150)助けてくれてありがとう、本当に解決する必要がありますこれ

4

4 に答える 4

2

ここで作業クエリ

create table Country
(CountryName varchar (50) not null,
Primary Key (CountryName));

create table InterestGroup
(IntrestgrpName varchar (30) not null,
Primary Key (IntrestgrpName));

create table Organisation
(OrgName varchar (50) not null,
OrgAddress varchar (30),
OrgTelNo varchar (30),
Primary Key (OrgName));

create table Qualification
(QualName varchar (50) not null,
Primary Key (QualName));

create table Member
(MemberID varchar (15) not null ,
MemberName varchar (30),
MemberAdd varchar (50) not null,
CountryName varchar (50) not null,
IntrestgrpName varchar (30) not null,
QualName varchar (50) not null,
OrgName varchar (50) not null,
Primary Key (MemberID), 
Foreign Key (CountryName) References Country (CountryName),
Foreign Key (IntrestgrpName) References InterestGroup (IntrestgrpName),
Foreign Key (QualName) References Qualification (Qualname),
Foreign Key (OrgName) References Organisation (OrgName));

デモはこちらSQLFIDDLE

于 2013-02-11T14:14:59.440 に答える
1

あなたのSQLは正しいです。次の変更で私のために働いた:

OrgTelNo.varchar (30) to OrgTelNo varchar (30)
于 2013-02-11T14:06:19.243 に答える
0

OrgTelNo.varchar (30),

これの代わりにあなたは書くべきです

OrgTelNo varchar (30),

また、最後のテーブルメンバーの作成におけるスペルミスです。

FOREIGN KEY ( IntrestgrpName ) REFERENCES InterestGroup ( IntrestgrpName)

代わりにこれを試してください。

于 2013-02-11T14:16:50.187 に答える
0
SHOW ENGINE INNODB STATUS;


...

------------------------
LATEST FOREIGN KEY ERROR
------------------------
130211 15:09:26 Error in foreign key constraint of table test/member:
Foreign Key (IntrestgrpName) References InterestGroup (InterestgrpName),
Foreign Key (QualName) References Qualification (Qualname),
Foreign Key (OrgName) References Organisation (OrgName)):
Cannot resolve column name close to:
),
Foreign Key (QualName) References Qualification (Qualname),
Foreign Key (OrgName) References Organisation (OrgName))

...

テーブルInterestGroupでInterestgrpNameという名前の列を参照しましたが、列の実際の名前はIntrestgrpNameです。

Foreign Key (IntrestgrpName) References InterestGroup (InterestgrpName),

You have type error here -----------------------------------^
于 2013-02-11T14:10:48.510 に答える