SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

DROP SCHEMA IF EXISTS `demo3db` ;
CREATE SCHEMA IF NOT EXISTS `demo3db` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `demo3db` ;

-- -----------------------------------------------------
-- Table `demo3db`.`personne`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `demo3db`.`personne` ;

CREATE  TABLE IF NOT EXISTS `demo3db`.`personne` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `nom` VARCHAR(45) NOT NULL ,
  `prenom` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`id`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `demo3db`.`numero_telephone`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `demo3db`.`numero_telephone` ;

CREATE  TABLE IF NOT EXISTS `demo3db`.`numero_telephone` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `numero_telephone` VARCHAR(45) NOT NULL ,
  `personne_idpersonne` INT NOT NULL ,
  INDEX `fk_numero_telephone_personne` (`personne_idpersonne` ASC) ,
  UNIQUE INDEX `numero_telephone_UNIQUE` (`numero_telephone` ASC) ,
  PRIMARY KEY (`id`) ,
  CONSTRAINT `fk_numero_telephone_personne`
    FOREIGN KEY (`personne_idpersonne` )
    REFERENCES `demo3db`.`personne` (`id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

-- -----------------------------------------------------
-- Data for table `demo3db`.`personne`
-- -----------------------------------------------------
START TRANSACTION;
USE `demo3db`;
INSERT INTO `demo3db`.`personne` (`id`, `nom`, `prenom`) VALUES (1, 'Durand', 'Jean');
INSERT INTO `demo3db`.`personne` (`id`, `nom`, `prenom`) VALUES (2, 'Dupond', 'Paul');

COMMIT;

-- -----------------------------------------------------
-- Data for table `demo3db`.`numero_telephone`
-- -----------------------------------------------------
START TRANSACTION;
USE `demo3db`;
INSERT INTO `demo3db`.`numero_telephone` (`id`, `numero_telephone`, `personne_idpersonne`) VALUES (NULL, '400000000', 1);
INSERT INTO `demo3db`.`numero_telephone` (`id`, `numero_telephone`, `personne_idpersonne`) VALUES (NULL, '600000000', 1);
INSERT INTO `demo3db`.`numero_telephone` (`id`, `numero_telephone`, `personne_idpersonne`) VALUES (NULL, '100000000', 2);

COMMIT;
