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


CREATE  TABLE IF NOT EXISTS `utilisateur` (
  `identifiant` VARCHAR(45) NOT NULL ,
  `mot_de_passe` VARCHAR(45) NOT NULL, 
  PRIMARY KEY (`identifiant`) )
ENGINE = InnoDB;

INSERT INTO utilisateur (identifiant, mot_de_passe) VALUES ('admin','pass');
INSERT INTO utilisateur (identifiant, mot_de_passe) VALUES ('root','password');

DROP PROCEDURE IF EXISTS inf340tddb.drop_user_if_exists ;
DELIMITER $$
CREATE PROCEDURE inf340tddb.drop_user_if_exists()
BEGIN
  DECLARE foo BIGINT DEFAULT 0 ;
  SELECT COUNT(*)
  INTO foo
    FROM mysql.user
      WHERE User = 'etudiant' and  Host = 'localhost';
   IF foo > 0 THEN
         DROP USER 'etudiant'@'localhost' ;
  END IF;
END ;$$
DELIMITER ;

CALL inf340tddb.drop_user_if_exists() ;
DROP PROCEDURE IF EXISTS inf340tddb.drop_users_if_exists ;



CREATE USER 'etudiant'@'localhost' IDENTIFIED BY 'perdu';
GRANT ALL PRIVILEGES  ON inf340tddb.* TO 'etudiant'@'localhost'
 WITH GRANT OPTION

