我已经搜索过问题但无法找到解决方案。
它是一对一的关系,我对另一个有员工FK的表有同样的问题
我一直在
error 1005 error no 105
表格结构
CREATE TABLE `staff` (
`StaffNumber` varchar(5) NOT NULL,
`Firstname` varchar(45) DEFAULT NULL,
`Lastname` varchar(45) DEFAULT NULL,
`Insertion` varchar(45) DEFAULT NULL,
PRIMARY KEY (`StaffNumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `airmarshall` (
`weaponNumber` int(11) NOT NULL,
`Nationality` varchar(45) NOT NULL,
`Snumber` varchar(5) NOT NULL,
`SnumberA` varchar(5) NOT NULL,
PRIMARY KEY (`Snumber`,`SnumberA`),
CONSTRAINT `staff_ibfk_1` FOREIGN KEY (`Snumber`) REFERENCES `staff` (`StaffNumber`)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8
答案 0 :(得分:0)
In Mysql Server version: 5.1.60
mysql> CREATE TABLE `staff` ( `StaffNumber` varchar(5) NOT NULL, `Firstname` varchar(45) DEFAULT NULL, `Lastname` varchar(45) DEFAULT NULL, `Insertion` varchar(45) DEFAULT NULL, PRIMARY KEY (`StaffNumber`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.15 sec)
mysql> CREATE TABLE `airmarshall` (
-> `weaponNumber` int(11) NOT NULL,
-> `Nationality` varchar(45) NOT NULL,
-> `Snumber` varchar(5) NOT NULL,
-> `SnumberA` varchar(5) NOT NULL,
-> PRIMARY KEY (`Snumber`,`SnumberA`),
-> CONSTRAINT `staff_ibfk_1` FOREIGN KEY (`Snumber`) REFERENCES `staff` (`StaffNumber`)
-> ON DELETE CASCADE ON UPDATE CASCADE
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.16 sec)
mysql> show create table airmarshall;
-----------------------------------+
| airmarshall | CREATE TABLE `airmarshall` (
`weaponNumber` int(11) NOT NULL,
`Nationality` varchar(45) NOT NULL,
`Snumber` varchar(5) NOT NULL,
`SnumberA` varchar(5) NOT NULL,
PRIMARY KEY (`Snumber`,`SnumberA`),
CONSTRAINT `staff_ibfk_1` FOREIGN KEY (`Snumber`) REFERENCES `staff` (`StaffNumber`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |