你知道外键在哪里有问题吗?
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
Table1 with Foreign key
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;
答案 0 :(得分:1)
ALTER TABLE `country` (
^^^^^--- should be CREATE
CREATE TABLE `perosn` (
^^^^^^--- should be person