0% found this document useful (0 votes)
9 views3 pages

TP 1

The document contains SQL statements to create a database called Gestion_auto_ecole with tables for students, CDs, sessions, attendance, questions and ordering of questions. It inserts sample data and performs various CRUD operations like updating, deleting and truncating tables.

Uploaded by

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

TP 1

The document contains SQL statements to create a database called Gestion_auto_ecole with tables for students, CDs, sessions, attendance, questions and ordering of questions. It inserts sample data and performs various CRUD operations like updating, deleting and truncating tables.

Uploaded by

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

show Databases;

use Gestion_auto_ecole;
show tables;

desc Question;

/*************Q1****************/
Create database Gestion_auto_ecole;
/****************Q2*************/
create table Apprenant(
IdApp int(10) primary key,
CINApp char(10) unique,
NomApp varchar(30) not null,
PrenomApp varchar(30) not null,
TeleApp char(10) unique,
VilleApp varchar(30) not null
);

create table CD(


IdCD int(10) primary key,
NomEditeur varchar(10) not null
);

create table Serie(


IdSerie int(10) primary key
);

create table Seance(


IdSeance int(10) primary key,
DateSeance date not null,
HeureSeance time not null,
IdSerie int(10),
IdCD int(10),
foreign key (IdSerie) references Serie(IdSerie) on update CASCADE on delete
RESTRICT,
foreign key (IdCD) references CD(IdCD)on update CASCADE on delete RESTRICT
);

/********Q3**********/
create table Assister(
IdApp int(10) primary key,
IdSeance int(10),
NoteSeance decimal(5),
foreign key (IdSeance) references Seance(IdSeance) on update CASCADE on delete
RESTRICT
);

create table Question(


IdQuestion int(10) primary key,
Intitule varchar(20),
Reponse varchar(100),
NiveauDificulte varchar(20),
Theme varchar(20)
);

create table OrdreQuestion(


IdQuestion int(10),
IdSerie int(10),
IdCD int(10),
NumOrdre int(20),
foreign key (IdQuestion) references Question(IdQuestion) on update CASCADE on
delete RESTRICT,
foreign key (IdSerie) references Serie(IdSerie)on update CASCADE on delete
RESTRICT,
foreign key (IdCD) references CD(IdCD)on update CASCADE on delete RESTRICT
);

/*********Q4***********/
alter table Assiter add primary key (IdApp,IdSeance);
alter table Question add primary key (IdQuestion);
alter table OrdreQuestion add primary key (IdQuestion,IdSerie,IdCD);
/***********Q5********/
alter table Assister add foreign key (IdApp) references Apprenant(IdApp) on update
cascade ON delete restrict;
alter table Assister add foreign key (IdSeance) references Seance(IdSeance) on
update cascade ON delete restrict;
alter table OrdreQuestion add foreign key(IdQuestion) references
Question(IdQuestion) on update cascade on delete restrict;
alter table OrdreQuestion add foreign key (IdSerie) references Serie(Idserie) on
update cascade on delete restrict;
alter table OrdreQuestion add foreign key (IdCD) references CD(IdCD) on update
cascade on delete restrict;
/*******Q6******/
alter table Serie ADD NomSerie varchar(20);
/******Q7********/
alter table Question modify intitule varchar(50);
/********Q8***********/
alter table Apprenant alter VilleApp set default 'SAFI';
/***********Q9********/
alter table Apprenant change TeleApp GSM_App char(10);
/**********Q10********/
alter table CD rename to CDROM;
/************Q11********/
insert into Apprenant(IdApp,CINApp,NomApp,PrenomApp,GSM_App,VilleApp)
values(1,'C000001', 'Allal' ,'Alea',0666676676,'SAFI'),
(2,'C000002', 'Nfisi' ,'Najib',07266262,'SAFI'),
(3,'C000003', 'Nadir' ,'Najat',09877888,'SOUIRA');
/*********Q12*********/
insert into Seance(IdSeance,DateSeance,HeureSeance,IdSerie,IdCD)
value(1,'2024-04-15','16:30:00' ,1,1);
/*********Q13*********/
insert into Assister (IdApp, IdSeance, NoteSeance)
values(1, 1, 18),
(2, 2, 20),
(3, 3, 15);
insert into Serie (idSerie,NomSerie)
values (1,'Serie1'),
(2,'Serie2'),
(3,'Serie3');
insert into CDROM (IdCD,NomEditeur)
values(1,'NOURALLAH'),
(2, 'OMAR'),
(3, 'MARWAN');

/****************Q14**************/
Update Apprenant Set IdApp=21 where IdAPP=1;

/*********Q15**********/
delete from Apprenant where IdApp=2;

/**********Q16*********/
delete from Apprenant where IdApp=3 and IdSeance=1;

/*********Q17********/

update Apprenant set VilleApp = 'El Jadida' where NomApp = 'Nfisi' and PrenomApp =
'Najib';
/**********Q18*******

truncate OrdreQuestion;
/***********19**********/
drop table

You might also like