为了测试,我建两张表:
SQL code
CREATE TABLE `tb_course` (
`AutoID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Cno` int(15) NOT NULL,
`Cname` varchar(20) NOT NULL,
PRIMARY KEY (`AutoID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL code
CREATE TABLE `tb_student` (
`AutoID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Sno` int(10) unsigned NOT NULL,
`Sname` varchar(20) DEFAULT NULL,
`Sage` tinyint(4) DEFAULT NULL,
`Cno` int(15) NOT NULL,
PRIMARY KEY (`AutoID`),
FOREIGN KEY (Cno) REFERENCES tb_course(Cno)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
tb_course表能成功建立,但是tb_student建立的时候,却提示出错了。
Can't create table 'hikkk_sea.tb_student' (errno: 150)
困于对mysql熟悉,请高手指教。
--转自