0% found this document useful (0 votes)
3 views

base donnee

The document outlines the SQL schema for a student management system, including tables for students, professors, subjects, and absences, along with constraints for data integrity. It also includes SQL commands to create views for calculating average grades and roles for user permissions. Additionally, it defines user accounts with specific access rights to the database tables and views.

Uploaded by

scuiro1
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

base donnee

The document outlines the SQL schema for a student management system, including tables for students, professors, subjects, and absences, along with constraints for data integrity. It also includes SQL commands to create views for calculating average grades and roles for user permissions. Additionally, it defines user accounts with specific access rights to the database tables and views.

Uploaded by

scuiro1
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE TABLE Etudiant (

NumEtudiant INT PRIMARY KEY,


Nom VARCHAR(100),
Prenom VARCHAR(100),
DateNaissance DATE,
Annee INT CHECK (Annee BETWEEN 1 AND 5)
);
CREATE TABLE Professeur (
NumProf INT PRIMARY KEY,
Nom VARCHAR(100),
Specialite VARCHAR(100),
DateRecrutement DATE,
Grade VARCHAR(50)
);
CREATE TABLE Matiere (
NumMatiere INT PRIMARY KEY,
Nom VARCHAR(100),
CoeffC FLOAT,
CoeffEx FLOAT,
NbHeures INT CHECK (NbHeures > 0)
);
CREATE TABLE Matiere (
NumMatiere INT PRIMARY KEY,
Nom VARCHAR(100),
CoeffC FLOAT,
CoeffEx FLOAT,
NbHeures INT CHECK (NbHeures > 0)
);
CREATE TABLE Absence (
NumEtudiant INT,
NumMatiere INT,
NbHeures INT CHECK (NbHeures > 0),
PRIMARY KEY (NumEtudiant, NumMatiere),
FOREIGN KEY (NumEtudiant) REFERENCES Etudiant(NumEtudiant),
FOREIGN KEY (NumMatiere) REFERENCES Matiere(NumMatiere)
);
2/
ALTER TABLE Note
ADD CONSTRAINT chk_NoteC CHECK (NoteC BETWEEN 0 AND 20),
ADD CONSTRAINT chk_NoteEx CHECK (NoteEx BETWEEN 0 AND 20),
ADD CONSTRAINT chk_TotalNote CHECK ((NoteC + NoteEx) <= 40);
ALTER TABLE Absence
ADD CONSTRAINT chk_NbHeures_Positive CHECK (NbHeures > 0),
ADD CONSTRAINT chk_NbHeures_Max CHECK (NbHeures <= 200);

3/
SELECT NumEtudiant, Nom, Prenom,
GREATEST(0, 20 - TRUNC(SUM(NbHeures)/2)) AS NoteAssiduite
FROM Absence
JOIN Etudiant ON Absence.NumEtudiant = Etudiant.NumEtudiant
GROUP BY NumEtudiant, Nom, Prenom;

4/
CREATE VIEW MoyenneMatiere AS
SELECT
NumEtudiant, NomPrenom, NumMatiere,
(NoteC * CoeffC + NoteEx * CoeffEx) / (CoeffC + CoeffEx) AS MoyMatiere
FROM Note
JOIN Etudiant ON Note.NumEtudiant = Etudiant.NumEtudiant;
5/
CREATE VIEW MoyenneGeneral AS
SELECT
NumEtudiant, NomPrenom,
AVG(MoyMatiere) AS Moyenne
FROM MoyenneMatiere
GROUP BY NumEtudiant, NomPrenom;

6/
CREATE VIEW MoyenneGeneral AS
SELECT
NumEtudiant, NomPrenom,
AVG(MoyMatiere) AS Moyenne
FROM MoyenneMatiere
GROUP BY NumEtudiant, NomPrenom;

CREATE ROLE ServiceAPOGEE;


GRANT SELECT, INSERT, UPDATE, DELETE ON Note TO ServiceAPOGEE;
GRANT SELECT, INSERT, UPDATE, DELETE ON Absence TO ServiceAPOGEE;
GRANT SELECT ON MoyenneGeneral TO ServiceAPOGEE;
GRANT SELECT ON MoyenneMatiere TO ServiceAPOGEE;

7/
CREATE USER U1_ServiceEtudiant IDENTIFIED BY 'password1';
GRANT ServiceEtudiant TO U1_ServiceEtudiant;

CREATE USER U1_ServiceAPOGEE IDENTIFIED BY 'password2';


GRANT ServiceAPOGEE TO U1_ServiceAPOGEE;

You might also like