1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| DROP TABLE IF EXISTS `tb_clazz`; CREATE TABLE `tb_clazz` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(18) NOT NULL, `name` varchar(18) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `tb_clazz` VALUES ('1', 'B151516', 'Java基础班'); DROP TABLE IF EXISTS `tb_student`; CREATE TABLE `tb_student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(18) DEFAULT NULL, `sex` varchar(18) DEFAULT NULL, `age` int(11) DEFAULT NULL, `clazz_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `clazz_id` (`clazz_id`), CONSTRAINT `tb_student_ibfk_1` FOREIGN KEY (`clazz_id`) REFERENCES `tb_clazz` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; INSERT INTO `tb_student` VALUES ('1', '小明', '男', '24', '1'); INSERT INTO `tb_student` VALUES ('2', '小王', '男', '23', '1'); INSERT INTO `tb_student` VALUES ('3', '小芳', '女', '22', '1'); INSERT INTO `tb_student` VALUES ('4', '小丽', '女', '22', '1');
|