Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 68b4ef1d rédigé par E214194U's avatar E214194U
Parcourir les fichiers

f

parent f6de90f1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -12,12 +12,27 @@ drop table employe;
--contraine unique et différée
alter table employe add CONSTRAINT U_empl unique(nuempl,affect);
alter table service add constraint fk_uempl foreign key(chef,nuserv)
alter table service drop constraint fk_nuempl;
alter table service add constraint fk_nuempl foreign key(chef,nuserv)
references employe(nuempl,affect)initially deferred;
alter table projet add constraint fk_utravail foreign key(resp,nuproj)
alter table projet drop constraint fk_utravail;
alter table projet add constraint fk_nutravail foreign key(resp,nuproj)
references travail(nuempl,nuproj)initially deferred;
alter table travail drop constraint fk_nuproj;
alter table travail add constraint fk_nuproj foreign key(nuproj)
references projet(nuproj)initially deferred;
alter table concerne drop constraint fk_nuproj2;
alter table concerne add constraint fk_nuproj2 foreign key(nuproj)
references projet(nuproj)initially deferred;
alter table travail add constraint fk_nuempl foreign key(nuempl)
references employe(nuempl)initially deferred;
insert into service values(88,'a',7);
insert into employe values(3,'a',0,88,2000);
commit;
......
--TD2
rollback;
--EXERCICE 1 :
/*create or replace TRIGGER modif_salaire after update
on employe for each row
BEGIN
if :new.salaire < :old.salaire then raise_application_error
(-20001,'viol de la règle :un salaire ne peut etre diminué') ;
end if ;
END;
create or replace TRIGGER augment_hebdo after update on employe for each row
BEGIN
if :new.hebdo > :old.hebdo then raise_application_error
(-20001,'viol de la règle : la durée hebdomadaire dun employé ne peut
pas augmenter') ;
end if;
END; */
/*
update employe
set employe.salaire = 0;
update employe
set employe.hebdo = 40;
*/
--EXERCICE 2 :
/*create or replace TRIGGER supprimer_employe after delete on employe
BEGIN
delete from travail where nuempl not in (select nuempl from employe);
END;
create or replace TRIGGER supprimer_projet after delete on projet
BEGIN
delete from travail where nuproj not in (select nuproj from projet);
delete from concerne where nuproj not in (select nuproj from projet);
END;
*/
/*
delete from employe where nuempl=14;
delete from projet where nuproj=135;
*/
--EXERCICE 3 :
CREATE OR REPLACE TRIGGER TRIG3 AFTER
insert or update ON Table2
DECLARE
REC_T1 T1%ROWTYPE;
BEGIN
SELECT * INTO REC_T1 FROM T1
WHERE Condition ;
//1 seul enregistrement trouvé en lève une exception
RAISE_APPLICATION_ERROR (numéro, message);//1
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;//0 enregist
WHEN TOO_MANY_ROWS THEN
RAISE_APPLICATION_ERROR ( ... );// 2 ou pl+
END;
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter