· 6 years ago · May 23, 2019, 09:24 AM
1-- phpMyAdmin SQL Dump
2-- version 4.8.3
3-- https://www.phpmyadmin.net/
4--
5-- Hôte : 127.0.0.1:3306
6-- Généré le : jeu. 23 mai 2019 à 09:16
7-- Version du serveur : 5.7.23
8-- Version de PHP : 7.2.10
9
10SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11SET AUTOCOMMIT = 0;
12START TRANSACTION;
13SET time_zone = "+00:00";
14
15
16/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
17/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
18/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
19/*!40101 SET NAMES utf8mb4 */;
20
21--
22-- Base de données : `lvs`
23--
24
25-- --------------------------------------------------------
26
27--
28-- Structure de la table `animaux`
29--
30
31DROP TABLE IF EXISTS `animaux`;
32CREATE TABLE IF NOT EXISTS `animaux` (
33 `Id` int(11) NOT NULL AUTO_INCREMENT,
34 `Nom` varchar(200) NOT NULL,
35 `Sexe` varchar(7) NOT NULL,
36 `DateNaissance` date DEFAULT NULL,
37 `IdTA` int(11) NOT NULL,
38 `Race` varchar(200) NOT NULL,
39 `idProprietaire` int(11) NOT NULL,
40 PRIMARY KEY (`Id`),
41 KEY `idProprietaire` (`idProprietaire`)
42) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
43
44--
45-- Déchargement des données de la table `animaux`
46--
47
48INSERT INTO `animaux` (`Id`, `Nom`, `Sexe`, `DateNaissance`, `IdTA`, `Race`, `idProprietaire`) VALUES
49(1, 'Butch', 'Male', '2017-11-07', 1, 'Berger Australien', 1),
50(2, 'Chien2', 'Male', '2019-05-22', 1, 'Doberman', 1),
51(3, 'Chienne3', 'Femelle', '2005-05-22', 1, 'Berger Allemand', 1),
52(4, 'Chienne4', 'Femelle', '2019-03-22', 1, 'Husky', 2);
53
54--
55-- Déclencheurs `animaux`
56--
57DROP TRIGGER IF EXISTS `TBD_Animaux`;
58DELIMITER $$
59CREATE TRIGGER `TBD_Animaux` BEFORE DELETE ON `animaux` FOR EACH ROW BEGIN
60
61 IF animaux.Sexe = 'Male' THEN
62 update statistiques set statistiques.NbMale = statistiques.NbMale-1, statistiques.NbAnimaux= statistiques.NbAnimaux-1;
63 END IF;
64 IF animaux.Sexe = 'Femelle' THEN
65 update statistiques set statistiques.NbFemelle = statistiques.NbFemelle-1, statistiques.NbAnimaux= statistiques.NbAnimaux-1;
66 END IF;
67END
68$$
69DELIMITER ;
70DROP TRIGGER IF EXISTS `TBI_Animaux`;
71DELIMITER $$
72CREATE TRIGGER `TBI_Animaux` BEFORE INSERT ON `animaux` FOR EACH ROW BEGIN
73
74 IF new.Sexe = 'Male' THEN
75 update statistiques set statistiques.NbMale = statistiques.NbMale+1, statistiques.NbAnimaux= statistiques.NbAnimaux+1;
76 END IF;
77 IF new.Sexe = 'Femelle' THEN
78 update statistiques set statistiques.NbFemelle = statistiques.NbFemelle+1, statistiques.NbAnimaux= statistiques.NbAnimaux+1;
79 END IF;
80END
81$$
82DELIMITER ;
83COMMIT;
84
85/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
86/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
87/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;