Home > database >  Help: ubantu16.04 using mysql to create a foreign key table tips can 't add foreign key constra
Help: ubantu16.04 using mysql to create a foreign key table tips can 't add foreign key constra

Time:10-03

The CREATE TABLE Dept (
Dno CHAR (2) PRIMARY KEY NOT NULL,
Dname CHAR (20),
Tele CHAR (9)
) engine=innodb;

The CREATE TABLE Course (
Cno CHAR (2) PRIMARY KEY NOT NULL,
The Subject CHAR (16) NOT NULL,
Time SMALLINT CHECK (Time> 0),
Credit SMALLINT CHECK (Credit> 0)
) engine=innodb;

The CREATE TABLE Student (
Sno CHAR (9) PRIMARY KEY NOT NULL,
The Name CHAR (8) NOT NULL,
Gen CHAR (2) the CHECK (Gen IN (' male ', 'woman')),
Birthday DATE,
Addr VARCHAR (20),
Dno CHAR (2),
# the CONSTRAINT 'fk_1'
FOREIGN KEY (Dno) REFERENCES Dept (Dno)
) engine=innodb;

The CREATE TABLE Class (
Classno CHAR (5) NOT NULL,
Num INT,
The Monitor CHAR (9),
PRIMARY KEY (Classno),
FOREIGN KEY REFERENCES (Monitor) Student (Sno)
) engine=innodb;
The CREATE TABLE Study (
Sno CHAR (9) NOT NULL,
Cno CHAR (2) NOT NULL,
Score a DECIMAL (5, 1),
PRIMARY KEY (Sno, Cno),
FOREIGN KEY REFERENCES (Sno) Student (Sno),
FOREIGN KEY REFERENCES (Cno) Course (Cno)
) engine=innodb;

CodePudding user response:

MySQL to the corresponding section, the my SQL Server, the other is your MySQL version is the same, and check your database configuration file, model that is different

CodePudding user response:

Build prompt foreign key problem which table?
  • Related