MySQL whats wrong with my foreign keys?

Posted by Skiy on Stack Overflow See other posts from Stack Overflow or by Skiy
Published on 2011-01-09T18:51:22Z Indexed on 2011/01/09 18:53 UTC
Read the original article Hit count: 197

Filed under:
|
|
|

Hello, what is wrong with the two foreign keys which I have marked with comments?

create database db; use db;

create table Flug(
Flugbez varchar(20),
FDatum Date,
Ziel varchar(20),
Flugzeit int,
Entfernung int,
Primary Key (Flugbez, FDatum));

create table Flugzeugtyp(
Typ varchar(20),
Hersteller varchar(20),
SitzAnzahl int,
Reisegeschw int,
primary key (Typ)
);

create table flugzeug(
Typ varchar(20),
SerienNr int,
AnschDatum Date,
FlugStd int,
primary key(Typ,SerienNr),
foreign key(Typ) references Flugzeugtyp(Typ));

create table Abflug(
Flugbez varchar(20),
FDatum Date,
Typ varchar(20),
Seriennr int,
Kaptaen varchar(20),
Primary key(Flugbez,FDatum,Typ,SerienNr),
Foreign key(Flugbez) references Flug(Flugbez),
-- Foreign key(FDatum) references Flug(FDatum),
Foreign key(Typ) references Flugzeugtyp(Typ)
-- ,Foreign key(SerienNr) references Flugzeug(SerienNr)
);

When I uncomment these, I get:

ERROR 1005 (HY000): Can't create table 'db.abflug' (errno: 150)

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql