CREATE TABLE DEPARTMENT ( Dname VARCHAR(15) NOT NULL,
Dnumber INT NOT NULL,
Mgr_ssn CHAR(9) NOT NULL,
Mgr_start_Date DATE,
PRIMARY KEY(Dnumber),
UNIQUE(Dname),
FOREIGN KEY(Mgr_ssn) REFERENCES EMPLOYEE (Ssn)
ON DELETE SET DEFAULT ON UPDATE CASCADE);
我是MySQL的初学者。上面的命令给了我这个:
无法添加外键约束
我试过SHOW ENGINE INNODB STATUS;
我检查了EMPLOYEE.Ssn的数据类型。
请帮忙。
编辑:我的EMPLOYEE表
| employee | CREATE TABLE `employee` (
`Fname` varchar(10) DEFAULT NULL,
`Minit` char(1) DEFAULT NULL,
`Lname` varchar(10) DEFAULT NULL,
`Ssn` char(9) NOT NULL,
`Bdate` date DEFAULT NULL,
`Address` varchar(40) DEFAULT NULL,
`Sex` char(1) DEFAULT NULL,
`Salary` int(11) DEFAULT NULL,
`Super_ssn` char(9) DEFAULT NULL,
`Dno` int(11) DEFAULT NULL,
PRIMARY KEY (`Ssn`),
KEY `Super_ssn` (`Super_ssn`),
CONSTRAINT `employee_ibfk_1` FOREIGN KEY (`Super_ssn`) REFERENCES `EMPLOYEE` (`Ssn`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
答案 0 :(得分:1)
根据https://dev.mysql.com/doc/refman/5.7/en/create-table-foreign-keys.html的MySQL文档,您无法在INNODB中使用SET DEFAULT:
SET DEFAULT: This action is recognized by the MySQL parser, but both InnoDB and NDB reject table definitions containing ON DELETE SET DEFAULT or ON UPDATE SET DEFAULT clauses