mysql自关联插入数据-级联地区

 

DROP TABLE IF EXISTS `booktest_areainfo`;

CREATE TABLE `booktest_areainfo` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(20) COLLATE utf8_bin NOT NULL,
  `parea_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `booktest_areai_parea_id_4c4f198f54b858a0_fk_booktest_areainfo_id` (`parea_id`),
  CONSTRAINT `booktest_areai_parea_id_4c4f198f54b858a0_fk_booktest_areainfo_id` FOREIGN KEY (`parea_id`) REFERENCES `booktest_areainfo` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

插入数据:、

INSERT INTO `test5`.`booktest_areainfo` VALUES ('610000',        '陕西省',        NULL);
INSERT INTO `test5`.`booktest_areainfo` VALUES ('610100',        '西安市',        '610000');
INSERT INTO `test5`.`booktest_areainfo` VALUES ('610101',        '市辖区',        '610100');
INSERT INTO `test5`.`booktest_areainfo` VALUES ('610102',        '新城区',        '610100');
INSERT INTO `test5`.`booktest_areainfo` VALUES ('610103',        '碑林区',        '610100');
INSERT INTO `test5`.`booktest_areainfo` VALUES ('610200',        '铜川市',        '610000');
INSERT INTO `test5`.`booktest_areainfo` VALUES ('610222',        '铜川市',        '610200');
INSERT INTO `test5`.`booktest_areainfo` VALUES ('610204',        '耀州区',        '610200');

 

posted on 2018-01-15 22:38  huodaihao  阅读(368)  评论(0编辑  收藏  举报

导航