您知道外键在哪里出问题吗?
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( `countryId` bigint(20) NOT NULL AUTO_INCREMENT, `personId` bigint(20) NOT ' at line 1
表1带外键
ALTER TABLE `country` (
`countryId` bigint(20) NOT NULL AUTO_INCREMENT,
`personId` bigint(20) NOT NULL,
`Name` varchar(5000) DEFAULT NULL,
PRIMARY KEY (`countryId`),
UNIQUE KEY `personId` (`personId`),
CONSTRAINT fk_PerOrders FOREIGN KEY (`personId`) REFERENCES perosn(`PersonId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PACK_KEYS=0;
表2
CREATE TABLE `perosn` (
`PersonId` bigint(20) NOT NULL AUTO_INCREMENT,
`Name` varchar(5000) DEFAULT NULL,
`Surname` varchar(5000) NOT NULL,
PRIMARY KEY (`PersonId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PACK_KEYS=0;
最佳答案
ALTER TABLE `country` (
^^^^^--- should be CREATE
CREATE TABLE `perosn` (
^^^^^^--- should be person
关于mysql - 外键-执行表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15204245/