0% found this document useful (0 votes)
1 views5 pages

Create database if it doesn

The document outlines SQL commands for creating a database and various tables, including User, Sécrétaire, Caissier, Coordonnateur, and others, with defined relationships and foreign keys. It establishes a structure for managing users, financial transactions, students, and their associated records. Each table is created with specific fields and constraints to ensure data integrity and relational connections.

Uploaded by

Elie Selemani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views5 pages

Create database if it doesn

The document outlines SQL commands for creating a database and various tables, including User, Sécrétaire, Caissier, Coordonnateur, and others, with defined relationships and foreign keys. It establishes a structure for managing users, financial transactions, students, and their associated records. Each table is created with specific fields and constraints to ensure data integrity and relational connections.

Uploaded by

Elie Selemani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

-- Create database if it doesn't exist

CREATE DATABASE IF NOT EXISTS dbfacky;

-- Use the newly created database

USE dbfacky;

-- 1. Create the User table first, as it's the parent in the "is-a" relationship

-- Table: User

CREATE TABLE IF NOT EXISTS User (

idUser INT PRIMARY KEY AUTO_INCREMENT,

Nom VARCHAR(255),

Postnom VARCHAR(255),

Prenom VARCHAR(255),

Sexe CHAR(1),

Fonction VARCHAR(255)

);

-- 2. Create the "role" tables, where their PK is also a FK to User

-- Table: Sécrétaire

CREATE TABLE IF NOT EXISTS Sécrétaire (

IdSec INT PRIMARY KEY, -- Primary key for Sécrétaire

FOREIGN KEY (IdSec) REFERENCES User(idUser) -- Also a foreign key to User

);

-- Table: Caissier

CREATE TABLE IF NOT EXISTS Caissier (

idcaiss INT PRIMARY KEY, -- Primary key for Caissier

FOREIGN KEY (idcaiss) REFERENCES User(idUser) -- Also a foreign key to User

);

-- Table: Coordonnateur
CREATE TABLE IF NOT EXISTS Coordonnateur (

idcoord INT PRIMARY KEY, -- Primary key for Coordonnateur

FOREIGN KEY (idcoord) REFERENCES User(idUser) -- Also a foreign key to User

);

-- 3. Create EntiteCompte, which references User

-- Table: Entité Compte

CREATE TABLE IF NOT EXISTS EntiteCompte (

Email VARCHAR(255) PRIMARY KEY,

Password VARCHAR(255),

iduser INT,

FOREIGN KEY (iduser) REFERENCES User(idUser)

);

-- 4. Create AgentBeneficiaire (no initial dependencies)

-- Table: AgentBeneficiaire

CREATE TABLE IF NOT EXISTS AgentBeneficiaire (

MatAgent INT PRIMARY KEY AUTO_INCREMENT,

NomAgent VARCHAR(255),

PostnomAgent VARCHAR(255),

PrenomAgent VARCHAR(255),

SexeAgent CHAR(1),

FonctionAgent VARCHAR(255),

SalaireBrut DECIMAL(10, 2),

Retenu DECIMAL(10, 2),

Prime DECIMAL(10, 2),

Salair_Net DECIMAL(10, 2)

);

-- 5. Create Depense, which references AgentBeneficiaire

-- Table: Depense
CREATE TABLE IF NOT EXISTS Depense (

IdDepense INT PRIMARY KEY AUTO_INCREMENT,

DateDepense DATE,

TypeDepense VARCHAR(255),

MontantDepense DECIMAL(10, 2),

Description TEXT,

MatAgent INT,

FOREIGN KEY (MatAgent) REFERENCES AgentBeneficiaire(MatAgent)

);

-- 6. Create Bon_de_sortie, which references Depense and AgentBeneficiaire

-- Table: Bon_de_sortie

CREATE TABLE IF NOT EXISTS Bon_de_sortie (

IdBonSortie INT PRIMARY KEY AUTO_INCREMENT,

IdDepense INT,

MatAgent INT,

Montant DECIMAL(10, 2),

Statut VARCHAR(50),

FOREIGN KEY (IdDepense) REFERENCES Depense(IdDepense),

FOREIGN KEY (MatAgent) REFERENCES AgentBeneficiaire(MatAgent)

);

-- 7. Create Eleves (no initial dependencies)

-- Table: Elèves

CREATE TABLE IF NOT EXISTS Eleves (

idEleve INT PRIMARY KEY AUTO_INCREMENT,

NomEleve VARCHAR(255),

PostnomEleve VARCHAR(255),

PrenomEleve VARCHAR(255),

Classe VARCHAR(50),

Sexe CHAR(1),
Datenaiss DATE

);

-- 8. Create Recu, which references Eleves

-- Table: Recu

CREATE TABLE IF NOT EXISTS Recu (

numrecu INT PRIMARY KEY AUTO_INCREMENT,

idEleve INT,

motif VARCHAR(255),

montant DECIMAL(10, 2),

datepaie DATE,

FOREIGN KEY (idEleve) REFERENCES Eleves(idEleve)

);

-- 9. Create Perception, which references Eleves and Recu

-- Table: Perception

CREATE TABLE IF NOT EXISTS Perception (

idpercept INT PRIMARY KEY AUTO_INCREMENT,

idEleve INT,

idrecu INT,

Motif VARCHAR(255),

Montant DECIMAL(10, 2),

Observ TEXT,

datepaie DATE,

FOREIGN KEY (idEleve) REFERENCES Eleves(idEleve),

FOREIGN KEY (idrecu) REFERENCES Recu(numrecu)

);

-- 10. Create Rapport_Finance, which references Perception, Depense, and Caissier

-- Table: Rapport_Finance

CREATE TABLE IF NOT EXISTS Rapport_Finance (


idrapport INT PRIMARY KEY AUTO_INCREMENT,

idpercept INT,

IdDepense INT,

date DATE,

idcaiss INT,

FOREIGN KEY (idpercept) REFERENCES Perception(idpercept),

FOREIGN KEY (IdDepense) REFERENCES Depense(IdDepense),

FOREIGN KEY (idcaiss) REFERENCES Caissier(idcaiss)

);

You might also like