Files
D3-A01BibliMVC/bibliotheque.sql
2025-09-11 11:25:49 +02:00

45 lines
1.3 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

DROP DATABASE IF EXISTS bdbibliotheque;
-- Base de données pour l'application Bibliothèque
CREATE DATABASE IF NOT EXISTS bdbibliotheque
DEFAULT CHARACTER SET utf8mb4
COLLATE utf8mb4_general_ci;
USE bdbibliotheque;
-- Table des catégories de livres
CREATE TABLE IF NOT EXISTS categories (
id INT AUTO_INCREMENT PRIMARY KEY,
nom VARCHAR(100)
);
-- Table des livres
CREATE TABLE IF NOT EXISTS livres (
id INT AUTO_INCREMENT PRIMARY KEY,
categorie INT NOT NULL,
titre VARCHAR(100) NOT NULL,
auteur VARCHAR(100) NOT NULL,
annee INT NOT NULL,
CONSTRAINT fk_livre_categorie
FOREIGN KEY (categorie)
REFERENCES categories (id)
);
-- Données de test
INSERT INTO categories (nom) VALUES
('Roman'),
('Manga'),
('Bande dessinée');
INSERT INTO livres (categorie, titre, auteur, annee) VALUES
(1, '1984', 'George Orwell', 1949),
(1, 'Le Petit Prince', 'Antoine de Saint-Exupéry', 1943),
(1, 'LÉtranger', 'Albert Camus', 1942),
(2, 'One Piece', 'Eiichirō Oda', 1997),
(2, 'Naruto', 'Masashi Kishimoto', 1999),
(2, 'Sun Ken Rock', 'Boichi', 2006),
(3, 'Astérix', 'René Goscinny', 1959);
-- Compte utilisateur administrateur pour accès distant à la base de données
CREATE USER 'adminBibli'@'%' IDENTIFIED BY 'mdpBibli';
GRANT ALL PRIVILEGES ON bdbibliotheque.* to "adminBibli"@"%";