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
|
DROP TABLE IF EXISTS `t_relation`;
DROP TABLE IF EXISTS `t_personne`;
-- -------------------------------------------
-- T_PERSONNE
-- -------------------------------------------
CREATE TABLE `t_personne` (
`id` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
`civilite` ENUM("","Mr","Mme","Mlle") NOT NULL,
`nom` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
KEY (`nom`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `t_personne` (`id`, `civilite`, `nom`) VALUES
(1, "Mr", "AA"),
(2, "Mr", "BB"),
(3, "Mme", "CC"),
(4, "Mme", "DD"),
(5, "", "EE"),
(6, "Mr", "FF");
-- -------------------------------------------
-- T_RELATION
-- -------------------------------------------
CREATE TABLE `t_relation` (
`id_personne_1` SMALLINT(5) UNSIGNED NOT NULL,
`id_personne_2` SMALLINT(5) UNSIGNED NOT NULL,
PRIMARY KEY (`id_personne_1`, `id_personne_2`),
FOREIGN KEY (`id_personne_1`) REFERENCES `t_personne` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (`id_personne_2`) REFERENCES `t_personne` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `t_relation` (`id_personne_1`, `id_personne_2`) VALUES
(1, 4), -- AA et DD sont en relation
(2, 1), -- BB et AA sont en relation
(3, 6), -- CC et FF sont en relation
(6, 4), -- FF et DD sont en relation
(6, 2); -- FF et BB sont en relation |
Partager