Les scripts SQL du schéma et des données sont détaillés ci-dessous.
DROP SCHEMA IF EXISTS `concession` ; CREATE SCHEMA IF NOT EXISTS `concession` DEFAULT CHARACTER SET utf8 ; USE `concession` ; -- ----------------------------------------------------- -- Table `concession`.`carburant` -- ----------------------------------------------------- DROP TABLE IF EXISTS `concession`.`carburant` ; CREATE TABLE IF NOT EXISTS `concession`.`carburant` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `nom` VARCHAR(45) NOT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB AUTO_INCREMENT = 12 DEFAULT CHARACTER SET = utf8; CREATE UNIQUE INDEX `nom_UNIQUE` ON `concession`.`carburant` (`nom` ASC); -- ----------------------------------------------------- -- Table `concession`.`couleur` -- ----------------------------------------------------- DROP TABLE IF EXISTS `concession`.`couleur` ; CREATE TABLE IF NOT EXISTS `concession`.`couleur` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `nom` VARCHAR(45) NOT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB AUTO_INCREMENT = 8 DEFAULT CHARACTER SET = utf8; CREATE UNIQUE INDEX `nom_UNIQUE` ON `concession`.`couleur` (`nom` ASC); -- ----------------------------------------------------- -- Table `concession`.`modele` -- ----------------------------------------------------- DROP TABLE IF EXISTS `concession`.`modele` ; CREATE TABLE IF NOT EXISTS `concession`.`modele` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `nom` VARCHAR(45) NULL DEFAULT NULL, `marque` VARCHAR(45) NULL DEFAULT NULL, `annee` INT(11) NULL DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB AUTO_INCREMENT = 12 DEFAULT CHARACTER SET = utf8; CREATE UNIQUE INDEX `uk_UNIQUE` ON `concession`.`modele` (`nom` ASC, `marque` ASC, `annee` ASC); -- ----------------------------------------------------- -- Table `concession`.`motorisation` -- ----------------------------------------------------- DROP TABLE IF EXISTS `concession`.`motorisation` ; CREATE TABLE IF NOT EXISTS `concession`.`motorisation` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `cylindree` INT(11) NOT NULL, `Chevaux` INT(11) NOT NULL, `id_carburant` INT(11) NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `fk_motorisation_carburant` FOREIGN KEY (`id_carburant`) REFERENCES `concession`.`carburant` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB AUTO_INCREMENT = 7 DEFAULT CHARACTER SET = utf8; CREATE UNIQUE INDEX `uk_UNIQUE` ON `concession`.`motorisation` (`cylindree` ASC, `Chevaux` ASC, `id_carburant` ASC); CREATE INDEX `fk_motorisation_carburant_idx` ON `concession`.`motorisation` (`id_carburant` ASC); -- ----------------------------------------------------- -- Table `concession`.`ville` -- ----------------------------------------------------- DROP TABLE IF EXISTS `concession`.`ville` ; CREATE TABLE IF NOT EXISTS `concession`.`ville` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `nom` VARCHAR(45) NULL DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB AUTO_INCREMENT = 5 DEFAULT CHARACTER SET = utf8; CREATE UNIQUE INDEX `nom_UNIQUE` ON `concession`.`ville` (`nom` ASC); -- ----------------------------------------------------- -- Table `concession`.`stock` -- ----------------------------------------------------- DROP TABLE IF EXISTS `concession`.`stock` ; CREATE TABLE IF NOT EXISTS `concession`.`stock` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `entrepot` VARCHAR(45) NOT NULL, `id_ville` INT(11) NULL DEFAULT NULL, PRIMARY KEY (`id`), CONSTRAINT `fk_stock_ville` FOREIGN KEY (`id_ville`) REFERENCES `concession`.`ville` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB AUTO_INCREMENT = 6 DEFAULT CHARACTER SET = utf8; CREATE UNIQUE INDEX `entrepot_UNIQUE` ON `concession`.`stock` (`entrepot` ASC); CREATE INDEX `fk_stock_ville_idx` ON `concession`.`stock` (`id_ville` ASC); -- ----------------------------------------------------- -- Table `concession`.`vehicule` -- ----------------------------------------------------- DROP TABLE IF EXISTS `concession`.`vehicule` ; CREATE TABLE IF NOT EXISTS `concession`.`vehicule` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `prix` DECIMAL(8,2) NULL DEFAULT NULL, `occasion` TINYINT(1) NOT NULL, `date_entree` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `id_stock` INT(11) NULL DEFAULT NULL, `id_modele` INT(11) NOT NULL, `id_couleur` INT(11) NOT NULL, `id_motorisation` INT(11) NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `fk_vehicule_couleur` FOREIGN KEY (`id_couleur`) REFERENCES `concession`.`couleur` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_vehicule_modele` FOREIGN KEY (`id_modele`) REFERENCES `concession`.`modele` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_vehicule_motorisation` FOREIGN KEY (`id_motorisation`) REFERENCES `concession`.`motorisation` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_vehicule_stock` FOREIGN KEY (`id_stock`) REFERENCES `concession`.`stock` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB AUTO_INCREMENT = 48 DEFAULT CHARACTER SET = utf8; CREATE UNIQUE INDEX `uk_UNIQUE` ON `concession`.`vehicule` (`date_entree` ASC, `occasion` ASC, `id_modele` ASC, `id_couleur` ASC, `id_motorisation` ASC); CREATE INDEX `fk_vehicule_stock_idx` ON `concession`.`vehicule` (`id_stock` ASC); CREATE INDEX `fk_vehicule_modele_idx` ON `concession`.`vehicule` (`id_modele` ASC); CREATE INDEX `fk_vehicule_couleur_idx` ON `concession`.`vehicule` (`id_couleur` ASC); CREATE INDEX `fk_vehicule_motorisation_idx` ON `concession`.`vehicule` (`id_motorisation` ASC); -- ----------------------------------------------------- -- Table `concession`.`vendeur` -- ----------------------------------------------------- DROP TABLE IF EXISTS `concession`.`vendeur` ; CREATE TABLE IF NOT EXISTS `concession`.`vendeur` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `nom` VARCHAR(45) NOT NULL, `prenom` VARCHAR(45) NOT NULL, `id_responsable` INT(11) NULL DEFAULT NULL, `id_ville` INT(11) NULL DEFAULT NULL, PRIMARY KEY (`id`), CONSTRAINT `fk_vendeur_responsable` FOREIGN KEY (`id_responsable`) REFERENCES `concession`.`vendeur` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_vendeur_ville` FOREIGN KEY (`id_ville`) REFERENCES `concession`.`ville` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB AUTO_INCREMENT = 7 DEFAULT CHARACTER SET = utf8; CREATE UNIQUE INDEX `uk_UNIQUE` ON `concession`.`vendeur` (`prenom` ASC, `nom` ASC); CREATE INDEX `fk_vendeur_responsable_idx` ON `concession`.`vendeur` (`id_responsable` ASC); CREATE INDEX `fk_vendeur_ville_idx` ON `concession`.`vendeur` (`id_ville` ASC); -- ----------------------------------------------------- -- Table `concession`.`vente` -- ----------------------------------------------------- DROP TABLE IF EXISTS `concession`.`vente` ; CREATE TABLE IF NOT EXISTS `concession`.`vente` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `date_heure` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `id_vendeur` INT(11) NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `fk_vente_vendeur` FOREIGN KEY (`id_vendeur`) REFERENCES `concession`.`vendeur` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8; CREATE UNIQUE INDEX `uk_UNIQUE` ON `concession`.`vente` (`date_heure` ASC, `id_vendeur` ASC); CREATE INDEX `fk_vente_vendeur_idx` ON `concession`.`vente` (`id_vendeur` ASC); -- ----------------------------------------------------- -- Table `concession`.`vehicule_vendu` -- ----------------------------------------------------- DROP TABLE IF EXISTS `concession`.`vehicule_vendu` ; CREATE TABLE IF NOT EXISTS `concession`.`vehicule_vendu` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `prix` DECIMAL(8,2) NOT NULL, `id_vehicule` INT(11) NOT NULL, `id_vente` INT(11) NOT NULL, PRIMARY KEY (`id`, `id_vente`), CONSTRAINT `fk_vehicule_vendu_vente1` FOREIGN KEY (`id_vente`) REFERENCES `concession`.`vente` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_vehicule_vendu_vehicule1` FOREIGN KEY (`id_vehicule`) REFERENCES `concession`.`vehicule` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8; CREATE INDEX `fk_vehicule_vendu_vente1_idx` ON `concession`.`vehicule_vendu` (`id_vente` ASC); CREATE INDEX `fk_vehicule_vendu_vehicule1_idx` ON `concession`.`vehicule_vendu` (`id_vehicule` ASC); CREATE UNIQUE INDEX `id_vehicule_UNIQUE` ON `concession`.`vehicule_vendu` (`id_vehicule` ASC);
USE concession; -- ville insert into `ville`(`id`,`nom`) values (1,'Nantes'); insert into `ville`(`id`,`nom`) values (4,'Rennes'); insert into `ville`(`id`,`nom`) values (2,'Saint-Nazaire'); insert into `ville`(`id`,`nom`) values (3,'Vannes'); -- vendeur insert into `vendeur`(`id`,`nom`,`prenom`,`id_responsable`,`id_ville`) values (2,'Leclerc','Jules',null,4); insert into `vendeur`(`id`,`nom`,`prenom`,`id_responsable`,`id_ville`) values (5,'Ksarin','Yann',null,null); insert into `vendeur`(`id`,`nom`,`prenom`,`id_responsable`,`id_ville`) values (1,'DuJardin','Charles',2,2); insert into `vendeur`(`id`,`nom`,`prenom`,`id_responsable`,`id_ville`) values (3,'Cadoret','Marie',5,2); insert into `vendeur`(`id`,`nom`,`prenom`,`id_responsable`,`id_ville`) values (4,'Lepine','Julie',5,3); insert into `vendeur`(`id`,`nom`,`prenom`,`id_responsable`,`id_ville`) values (6,'Dubigeon','Laure',2,4); insert into `vendeur`(`id`,`nom`,`prenom`,`id_responsable`,`id_ville`) values (7,'Castel','Yann',5,4); -- stock insert into `stock`(`id`,`entrepot`,`id_ville`) values (1,'NA1',1); insert into `stock`(`id`,`entrepot`,`id_ville`) values (2,'SA1',2); insert into `stock`(`id`,`entrepot`,`id_ville`) values (3,'VA1',3); insert into `stock`(`id`,`entrepot`,`id_ville`) values (4,'RE1',4); insert into `stock`(`id`,`entrepot`,`id_ville`) values (5,'RE2',4); -- couleur insert into `couleur`(`id`,`nom`) values (4,'blanc'); insert into `couleur`(`id`,`nom`) values (3,'bleu'); insert into `couleur`(`id`,`nom`) values (7,'gris'); insert into `couleur`(`id`,`nom`) values (5,'jaune'); insert into `couleur`(`id`,`nom`) values (6,'noir'); insert into `couleur`(`id`,`nom`) values (1,'rouge'); insert into `couleur`(`id`,`nom`) values (2,'vert'); -- carburant insert into `carburant`(`id`,`nom`) values (8,'diesel'); insert into `carburant`(`id`,`nom`) values (10,'electrique'); insert into `carburant`(`id`,`nom`) values (7,'essence'); insert into `carburant`(`id`,`nom`) values (9,'gaz'); insert into `carburant`(`id`,`nom`) values (11,'hybride'); -- motorisation insert into `motorisation`(`id`,`cylindree`,`Chevaux`,`id_carburant`) values (5,170,2,10); insert into `motorisation`(`id`,`cylindree`,`Chevaux`,`id_carburant`) values (7,1200,4,7); insert into `motorisation`(`id`,`cylindree`,`Chevaux`,`id_carburant`) values (6,1200,4,11); insert into `motorisation`(`id`,`cylindree`,`Chevaux`,`id_carburant`) values (3,1200,6,7); insert into `motorisation`(`id`,`cylindree`,`Chevaux`,`id_carburant`) values (4,1400,5,8); insert into `motorisation`(`id`,`cylindree`,`Chevaux`,`id_carburant`) values (1,1600,6,8); insert into `motorisation`(`id`,`cylindree`,`Chevaux`,`id_carburant`) values (2,1600,7,7); -- modele insert into `modele`(`id`,`nom`,`marque`,`annee`) values (4,'440','VOLVO',1996); insert into `modele`(`id`,`nom`,`marque`,`annee`) values (12,'4L','RENAULT',1970); insert into `modele`(`id`,`nom`,`marque`,`annee`) values (2,'A8','AUDI',2007); insert into `modele`(`id`,`nom`,`marque`,`annee`) values (1,'A8','AUDI',2013); insert into `modele`(`id`,`nom`,`marque`,`annee`) values (7,'C3','CITROEN',2017); insert into `modele`(`id`,`nom`,`marque`,`annee`) values (8,'C3 CROSS','CITROEN',2017); insert into `modele`(`id`,`nom`,`marque`,`annee`) values (11,'Captur','RENAULT',2017); insert into `modele`(`id`,`nom`,`marque`,`annee`) values (9,'CORSA','OPEN',2017); insert into `modele`(`id`,`nom`,`marque`,`annee`) values (5,'CTS','CADILLAC',2015); insert into `modele`(`id`,`nom`,`marque`,`annee`) values (3,'Grand Cherokee','JEEP',2011); insert into `modele`(`id`,`nom`,`marque`,`annee`) values (6,'ix20','HYUNDAI',2017); insert into `modele`(`id`,`nom`,`marque`,`annee`) values (10,'Kangoo','RENAULT',2017); -- vehicule insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (12,25000.00,0,'2018-04-13 13:52:28',1,7,2,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (13,41000.00,0,'2018-04-13 13:52:28',2,7,4,1); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (14,12630.00,1,'2018-04-13 13:52:28',1,8,1,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (15,15000.00,0,'2018-04-13 13:52:28',4,5,5,3); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (25,52630.00,1,'2018-03-18 12:52:28',1,11,1,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (26,52630.00,1,'2018-03-18 12:52:28',1,10,1,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (27,52630.00,1,'2018-03-18 12:52:28',1,10,4,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (28,52630.00,1,'2018-03-18 12:52:28',1,10,4,1); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (29,52630.00,1,'2018-03-18 12:52:28',1,10,4,4); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (30,52630.00,1,'2018-03-18 12:52:28',1,10,4,3); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (31,52630.00,1,'2018-03-18 12:52:28',1,3,4,3); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (32,52630.00,1,'2018-03-18 12:52:28',1,3,4,1); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (33,52630.00,1,'2018-03-18 12:52:28',1,3,4,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (34,52630.00,1,'2018-03-18 12:52:28',2,4,1,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (35,52630.00,1,'2018-03-18 12:52:28',2,5,1,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (36,52630.00,1,'2018-03-18 12:52:28',2,6,1,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (38,52630.00,1,'2018-03-18 12:52:28',2,11,1,5); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (39,52630.00,1,'2018-03-18 12:52:28',2,8,1,5); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (40,52630.00,1,'2018-03-18 12:52:28',2,8,1,4); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (41,52630.00,1,'2018-03-18 12:52:28',2,8,2,4); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (42,52630.00,1,'2018-03-18 12:52:28',2,8,3,4); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (43,52630.00,1,'2018-03-18 12:52:28',2,8,4,4); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (44,52630.00,1,'2018-04-13 16:42:42',null,8,4,4); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (45,52630.00,0,'2018-04-13 16:43:03',null,11,4,4); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (46,52630.00,0,'2018-04-13 16:43:09',null,5,4,4); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (47,52630.00,0,'2018-04-13 16:43:18',null,5,1,4); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (48,10000.00,1,'2018-04-17 19:00:33',3,1,1,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (49,5000.00,1,'2018-04-17 20:39:18',3,2,1,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (50,5000.00,1,'2018-04-17 20:46:44',3,2,1,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (51,2000.00,1,'2018-04-17 21:11:40',1,12,4,7); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (52,2000.00,1,'2018-04-17 21:30:44',1,12,4,7); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (57,50000.00,1,'2018-04-23 11:16:57',null,11,1,2); insert into `vehicule`(`id`,`prix`,`occasion`,`date_entree`,`id_stock`,`id_modele`,`id_couleur`,`id_motorisation`) values (58,15000.00,1,'2018-04-23 11:16:57',null,10,4,3); -- vente insert into `vente`(`id`,`date_heure`,`id_vendeur`) values (38,'2018-04-20 18:26:01',4); insert into `vente`(`id`,`date_heure`,`id_vendeur`) values (51,'2018-04-23 11:16:57',4); -- vehicule vendu insert into `vehicule_vendu`(`id`,`prix`,`id_vehicule`,`id_vente`) values (8,50000.00,25,38); insert into `vehicule_vendu`(`id`,`prix`,`id_vehicule`,`id_vente`) values (9,15000.00,30,38); insert into `vehicule_vendu`(`id`,`prix`,`id_vehicule`,`id_vente`) values (16,50000.00,57,51); insert into `vehicule_vendu`(`id`,`prix`,`id_vehicule`,`id_vente`) values (17,15000.00,58,51);
A vous de jouer…
Pas tout de suite !