简体   繁体   中英

MySQL Foreign Key syntax error

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);

I am a beginner in MySQL. The command above gives me this:

Cannot add foreign key constraint

I have tried SHOW ENGINE INNODB STATUS; I checked EMPLOYEE.Ssn's data type. Please help.

Edit: My EMPLOYEE table

| 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 |

根据https://dev.mysql.com/doc/refman/5.7/en/create-table-foreign-keys.html上的MySQL文档,您不能将SET DEFAULT与INNODB结合使用:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM