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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| use mybatis;
DROP TABLE IF EXISTS `tb_user`; CREATE TABLE `tb_user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(18) DEFAULT NULL, `loginname` varchar(18) NOT NULL, `password` varchar(18) NOT NULL, `phone` varchar(18) DEFAULT NULL, `address` varchar(18) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `tb_user` VALUES ('1', '小明', 'xiaoming', 'xiaoming', '123456789123', '北京');
DROP TABLE IF EXISTS `tb_article`; CREATE TABLE `tb_article` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(18) DEFAULT NULL, `price` double DEFAULT NULL, `remark` varchar(18) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `tb_article` VALUES ('1', '商品1', '123.12', 'xxx的伟大著作'); INSERT INTO `tb_article` VALUES ('2', '商品2', '12.3', 'yyy的伟大著作'); INSERT INTO `tb_article` VALUES ('3', '商品3', '34.22', 'zzz的著作');
DROP TABLE IF EXISTS `tb_order`; CREATE TABLE `tb_order` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(32) DEFAULT NULL, `total` double DEFAULT NULL, `user_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), CONSTRAINT `tb_order_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `tb_user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `tb_order` VALUES ('1', 'abcseeeahoaugoeijgiej', '223.33', '1'); INSERT INTO `tb_order` VALUES ('2', 'sfaofosfhodsfuefie', '111.22', '1');
DROP TABLE IF EXISTS `tb_item`; CREATE TABLE `tb_item` ( `order_id` int(11) NOT NULL DEFAULT '0', `article_id` int(11) NOT NULL DEFAULT '0', `amount` int(11) DEFAULT NULL, PRIMARY KEY (`order_id`,`article_id`), KEY `article_id` (`article_id`), CONSTRAINT `tb_item_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `tb_order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `tb_item_ibfk_2` FOREIGN KEY (`article_id`) REFERENCES `tb_article` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `tb_item` VALUES ('1', '1', '1'); INSERT INTO `tb_item` VALUES ('1', '2', '1'); INSERT INTO `tb_item` VALUES ('1', '3', '3'); INSERT INTO `tb_item` VALUES ('2', '1', '2'); INSERT INTO `tb_item` VALUES ('2', '2', '3');
|