create table Employee
(
ssn INTEGER not null unique,
Name varchar(30) not null,
Address varchar(30) not null,
Age INTEGER not null,
Sex varchar(10) not null,
Position varchar(20) not null,
primary key(ssn)
)ENGINE=InnoDB;
create table Department
(
DId INTEGER not null unique,
Dname varchar(15) not null,
ManagerId INTEGER not null unique,
primary key(DId)
);
create table Works_In
(
ssn INTEGER not null unique,
DId INTEGER not null unique,
since varchar(15) not null,
primary key(ssn,DId),
FOREIGN KEY(ssn,DId) REFERENCES Employee(ssn) ON DELETE CASCADE ON UPDATE CASCADE
FOREIGN KEY(DId) REFERENCES Department(DId) ON DELETE CASCADE ON UPDATE CASCADE为什么
)ENGINE=InnoDB;
在Works_In中给Employee和Department加两个外键
这样为什么不行?
ERROR 1005 (HY000) at line 62: Can't create table './HumanResources/Works_In.frm' (errno: 150)
应该怎么样写?
(
ssn INTEGER not null unique,
Name varchar(30) not null,
Address varchar(30) not null,
Age INTEGER not null,
Sex varchar(10) not null,
Position varchar(20) not null,
primary key(ssn)
)ENGINE=InnoDB;
create table Department
(
DId INTEGER not null unique,
Dname varchar(15) not null,
ManagerId INTEGER not null unique,
primary key(DId)
);
create table Works_In
(
ssn INTEGER not null unique,
DId INTEGER not null unique,
since varchar(15) not null,
primary key(ssn,DId),
FOREIGN KEY(ssn,DId) REFERENCES Employee(ssn) ON DELETE CASCADE ON UPDATE CASCADE
FOREIGN KEY(DId) REFERENCES Department(DId) ON DELETE CASCADE ON UPDATE CASCADE为什么
)ENGINE=InnoDB;
在Works_In中给Employee和Department加两个外键
这样为什么不行?
ERROR 1005 (HY000) at line 62: Can't create table './HumanResources/Works_In.frm' (errno: 150)
应该怎么样写?
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.htmlcreate table Works_In
(
ssn INTEGER not null unique,
DId INTEGER not null unique,
since varchar(15) not null,
primary key(ssn,DId),
FOREIGN KEY(ssn
,DId) REFERENCES Employee(ssn) ON DELETE CASCADE ON UPDATE CASCADEFOREIGN KEY(DId) REFERENCES Department(DId) ON DELETE CASCADE ON UPDATE CASCADE为什么
)ENGINE=InnoDB;mysql> create table Works_In
-> (
-> ssn INTEGER not null unique,
-> DId INTEGER not null unique,
-> since varchar(15) not null,
-> primary key(ssn,DId),
-> FOREIGN KEY(DId) REFERENCES Employee(ssn) ON DELETE CASCADE ON UPDATE CASCADE,
-> FOREIGN KEY(DId) REFERENCES Department(DId) ON DELETE CASCADE ON UPDATE CASCADE
-> )ENGINE=InnoDB;
Query OK, 0 rows affected (0.13 sec)mysql>
(
ssn INTEGER not null unique,
Name varchar(30) not null,
Address varchar(30) not null,
Age INTEGER not null,
Sex varchar(10) not null,
Position varchar(20) not null,
primary key(ssn)
)ENGINE=InnoDB;
create table Department
(
DId INTEGER not null unique,
Dname varchar(15) not null,
ManagerId INTEGER not null unique,
primary key(DId)
);
create table Works_In
(
ssn INTEGER not null unique,
DId INTEGER not null unique,
since varchar(15) not null,
primary key(ssn,DId),
FOREIGN KEY(ssn) REFERENCES Employee(ssn) ON DELETE CASCADE ON UPDATE CASCADE
FOREIGN KEY(DId) REFERENCES Department(DId) ON DELETE CASCADE ON UPDATE CASCADE为什么
)ENGINE=InnoDB;
在Works_In中给Employee和Department加两个外键
这样为什么不行?
ERROR 1005 (HY000) at line 62: Can't create table './HumanResources/Works_In.frm' (errno: 150)
应该怎么样写?
-> FOREIGN KEY(DId) REFERENCES Employee(ssn) ON DELETE CASCADE ON UPDATE CASCADE,
而是
FOREIGN KEY(ssn) REFERENCES Employee(ssn) ON DELETE CASCADE ON UPDATE CASCADE
问题依然存在
(
ssn INTEGER not null unique,
DId INTEGER not null unique,
since varchar(15) not null,
primary key(ssn,DId),
FOREIGN KEY(ssn) REFERENCES Employee(ssn) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(DId) REFERENCES Department(DId) ON DELETE CASCADE ON UPDATE CASCADE
)ENGINE=InnoDB;
create table Employee
(
ssn INTEGER not null unique,
Name varchar(30) not null,
Address varchar(30) not null,
Age INTEGER not null,
Sex varchar(10) not null,
Position varchar(20) not null,
primary key(ssn)
)ENGINE=InnoDB;
create table Department
(
DId INTEGER not null unique,
Dname varchar(15) not null,
ManagerId INTEGER not null unique,
primary key(DId)
);create table Works_In
(
ssn INTEGER not null unique,
DId INTEGER not null unique,
since varchar(15) not null,
primary key(ssn,DId),
FOREIGN KEY(ssn) REFERENCES Employee(ssn) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(DId) REFERENCES Department(DId) ON DELETE CASCADE ON UPDATE CASCADE
)ENGINE=InnoDB;
完整代码就是这样,第三个表是完全复制您的代码的。