Script SQL Générique
-- Création des tables principales
CREATE TABLE Table1 (
ID_Table1 INT PRIMARY KEY AUTO_INCREMENT, -- Clé primaire unique
Attribut1 VARCHAR(50) NOT NULL, -- Exemple d'attribut textuel
Attribut2 INT NOT NULL, -- Exemple d'attribut numérique
Attribut3 DATE -- Exemple d'attribut de type date
);
CREATE TABLE Table2 (
ID_Table2 INT PRIMARY KEY AUTO_INCREMENT,
Attribut1 VARCHAR(100) NOT NULL,
Attribut2 DECIMAL(10, 2), -- Exemple d'attribut monétaire
Attribut3 BOOLEAN DEFAULT FALSE -- Exemple d'attribut booléen
);
-- Table intermédiaire pour une relation N:N entre Table1 et Table2
CREATE TABLE Table1_Table2 (
ID_Table1 INT NOT NULL, -- Référence vers Table1
ID_Table2 INT NOT NULL, -- Référence vers Table2
Attribut_Relation VARCHAR(50), -- Exemple d'attribut spécifique à la relation
PRIMARY KEY (ID_Table1, ID_Table2), -- Clé primaire composite
FOREIGN KEY (ID_Table1) REFERENCES Table1(ID_Table1) ON DELETE CASCADE,
FOREIGN KEY (ID_Table2) REFERENCES Table2(ID_Table2) ON DELETE CASCADE
);
-- Table pour une relation 1:N entre Table1 et Table3
CREATE TABLE Table3 (
ID_Table3 INT PRIMARY KEY AUTO_INCREMENT,
Attribut1 VARCHAR(50),
ID_Table1 INT NOT NULL, -- Clé étrangère vers Table1
FOREIGN KEY (ID_Table1) REFERENCES Table1(ID_Table1) ON DELETE SET NULL
);
-- Table pour une relation 1:1 entre Table2 et Table4
CREATE TABLE Table4 (
ID_Table4 INT PRIMARY KEY AUTO_INCREMENT,
Attribut1 DATE NOT NULL,
ID_Table2 INT UNIQUE, -- Relation 1:1 (clé étrangère unique)
FOREIGN KEY (ID_Table2) REFERENCES Table2(ID_Table2) ON DELETE CASCADE
);