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

Creating the database

The document outlines the SQL commands for creating a university management database named 'Gestion_universite' with tables for students, professors, departments, courses, enrollments, and grades. Each table includes primary keys and foreign key constraints to establish relationships between them. Additionally, there are comments indicating the purpose of each table and the structure of the data to be stored.

Uploaded by

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

Creating the database

The document outlines the SQL commands for creating a university management database named 'Gestion_universite' with tables for students, professors, departments, courses, enrollments, and grades. Each table includes primary keys and foreign key constraints to establish relationships between them. Additionally, there are comments indicating the purpose of each table and the structure of the data to be stored.

Uploaded by

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

-- Creating the database "Gestion_universite" nom VARCHAR(20), -- Professor's last name

CREATE DATABASE Gestion_universite; prenom VARCHAR(20), -- Professor's first name

email VARCHAR(30), -- Professor's email address

-- Selecting the database for use id_depart VARCHAR(20) -- Foreign key referencing department

USE Gestion_universite; );

-- Creating the "Etudiant" table to store student information -- Adding a primary key constraint to "Professeur" table

CREATE TABLE Etudiant ( ALTER TABLE Professeur ADD PRIMARY KEY(id_prof);

id_etudiant VARCHAR(20), -- Unique identifier for students

nom VARCHAR(20), -- Student's last name -- Creating the "Departement" table to store department information

prenom VARCHAR(20), -- Student's first name CREATE TABLE Departement (

date_naissance DATE, -- Student's date of birth id_depart VARCHAR(20) PRIMARY KEY, -- Unique identifier for department

email VARCHAR(30) -- Student's email address nom_depart VARCHAR(20) -- Name of the department

); );

-- Adding a primary key constraint to "Etudiant" table -- Creating the "Cours" table to store course information

ALTER TABLE Etudiant ADD PRIMARY KEY(id_etudiant); CREATE TABLE Cours (

id_cours VARCHAR(20) PRIMARY KEY, -- Unique identifier for courses

-- Creating the "Professeur" table to store professor information nom_cours VARCHAR(20) -- Name of the course

CREATE TABLE Professeur ( );

id_prof VARCHAR(20), -- Unique identifier for professors


-- Creating the "Inscription" table to store student course enrollments

CREATE TABLE Inscription ( -- Adding a foreign key constraint to link "Professeur" with "Departement"

id_inscript VARCHAR(20) PRIMARY KEY, -- Unique identifier for each enrollment ALTER TABLE Professeur ADD CONSTRAINT FK_id_depart FOREIGN KEY(id_depart)
REFERENCES Departement(id_depart);
date_inscript DATE, -- Date of enrollment

id_cours VARCHAR(20), -- Foreign key referencing "Cours"


-- Attempting to add a foreign key in "Departement" referencing "Professeur"
id_etudiant VARCHAR(20) -- Foreign key referencing "Etudiant"
-- (This creates a circular dependency, which is not allowed. It should be removed
); or redesigned.)

ALTER TABLE Departement ADD CONSTRAINT FK_id_prof FOREIGN KEY(id_prof)


-- Adding foreign key constraints to "Inscription" table REFERENCES Professeur(id_prof);

ALTER TABLE Inscription ADD CONSTRAINT FK_id_cours FOREIGN KEY(id_cours)


REFERENCES Cours(id_cours); -- Adding foreign key constraints to "Notes" table
ALTER TABLE Inscription ADD CONSTRAINT FK_id_etudiant FOREIGN ALTER TABLE Notes ADD CONSTRAINT FK_id_cours FOREIGN KEY(id_cours)
KEY(id_etudiant) REFERENCES Etudiant(id_etudiant); REFERENCES Cours(id_cours);

ALTER TABLE Notes ADD CONSTRAINT FK_id_etudiant FOREIGN KEY(id_etudiant)


-- Creating the "Notes" table to store student grades REFERENCES Etudiant(id_etudiant);

CREATE TABLE Notes (

id_note VARCHAR(20) PRIMARY KEY, -- Unique identifier for each grade entry

note_obtenue FLOAT, -- Grade obtained

id_cours VARCHAR(20), -- Foreign key referencing "Cours"

id_etudiant VARCHAR(20) -- Foreign key referencing "Etudiant"

);

You might also like