TP2++
This commit is contained in:
parent
bc20e779a3
commit
356d24ff77
80
TP2.sql
80
TP2.sql
@ -72,9 +72,35 @@ BEGIN
|
|||||||
INSERT INTO Client_His (id, prenom, nom, email, ville, date_suppression)
|
INSERT INTO Client_His (id, prenom, nom, email, ville, date_suppression)
|
||||||
VALUES (:OLD.id, :OLD.prenom, :OLD.nom, :OLD.email, :OLD.ville, SYSDATE);
|
VALUES (:OLD.id, :OLD.prenom, :OLD.nom, :OLD.email, :OLD.ville, SYSDATE);
|
||||||
|
|
||||||
DELETE FROM Commande WHERE client_id = :OLD.id;
|
DELETE FROM Commande3 WHERE client_id = :OLD.id;
|
||||||
|
|
||||||
DELETE FROM ligne_commande WHERE commande_id IN (SELECT id FROM Commande WHERE client_id = :OLD.id);
|
DELETE FROM ligne_commande WHERE commande_id IN (SELECT id FROM Commande3 WHERE client_id = :OLD.id);
|
||||||
|
END;
|
||||||
|
|
||||||
|
//Exo 5 :
|
||||||
|
//Exo 2
|
||||||
|
|
||||||
|
//1/
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
DELETE FROM ligne_commande WHERE commande_id = :commande_id;
|
||||||
|
|
||||||
|
DELETE FROM Commande3 WHERE id = :commande_id;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
//2/
|
||||||
|
ALTER TABLE ligne_commande
|
||||||
|
ADD CONSTRAINT fk_ligne_commande_commande
|
||||||
|
FOREIGN KEY (commande_id)
|
||||||
|
REFERENCES Commande3(id)
|
||||||
|
ON DELETE CASCADE;
|
||||||
|
|
||||||
|
//3/
|
||||||
|
CREATE PROCEDURE SupprimerCommande (p_commande_id INT) AS
|
||||||
|
BEGIN
|
||||||
|
DELETE FROM ligne_commande WHERE commande_id = p_commande_id;
|
||||||
|
DELETE FROM Commande3 WHERE id = p_commande_id;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
|
|
||||||
@ -119,7 +145,7 @@ CREATE TABLE ligne_commande (
|
|||||||
produit_id INT,
|
produit_id INT,
|
||||||
quantite INT,
|
quantite INT,
|
||||||
prix_total DECIMAL(10,2),
|
prix_total DECIMAL(10,2),
|
||||||
FOREIGN KEY (commande_id) REFERENCES Commande(id) ON DELETE CASCADE
|
FOREIGN KEY (commande_id) REFERENCES Commande3(id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -127,12 +153,12 @@ CREATE TABLE ligne_commande (
|
|||||||
|
|
||||||
CREATE TABLE CommandeAuditLog (
|
CREATE TABLE CommandeAuditLog (
|
||||||
Utilisateur VARCHAR(50),
|
Utilisateur VARCHAR(50),
|
||||||
ActionSQL VARCHAR(3), -- 'INS', 'DEL', ou 'UPD'
|
ActionSQL VARCHAR(3),
|
||||||
DateMAJ DATE DEFAULT SYSDATE,
|
DateMAJ DATE DEFAULT SYSDATE,
|
||||||
ActCol VARCHAR(255)
|
ActCol VARCHAR(255)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TRIGGER trg_AuditInsertCommande
|
CREATE OR REPLACE TRIGGER trg_AuditInsertCommande
|
||||||
AFTER INSERT ON Commande
|
AFTER INSERT ON Commande
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -140,7 +166,7 @@ BEGIN
|
|||||||
VALUES (USER, 'INS', SYSDATE, 'N/A');
|
VALUES (USER, 'INS', SYSDATE, 'N/A');
|
||||||
END;
|
END;
|
||||||
|
|
||||||
CREATE TRIGGER trg_AuditDeleteCommande
|
CREATE OR REPLACE TRIGGER trg_AuditDeleteCommande
|
||||||
AFTER DELETE ON Commande
|
AFTER DELETE ON Commande
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -148,24 +174,30 @@ BEGIN
|
|||||||
VALUES (USER, 'DEL', SYSDATE, 'N/A');
|
VALUES (USER, 'DEL', SYSDATE, 'N/A');
|
||||||
END;
|
END;
|
||||||
|
|
||||||
CREATE TRIGGER trg_AuditUpdateCommande
|
CREATE OR REPLACE TRIGGER trg_AfterUpdateCommande3
|
||||||
AFTER UPDATE ON Commande
|
AFTER UPDATE ON Commande3
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE modified_columns VARCHAR(255);
|
|
||||||
|
DECLARE
|
||||||
SET modified_columns = '';
|
modified_columns VARCHAR2(255);
|
||||||
|
BEGIN
|
||||||
IF :OLD.date_achat != :NEW.date_achat THEN
|
|
||||||
SET modified_columns = CONCAT(modified_columns, 'date_achat, ');
|
modified_columns := '';
|
||||||
END IF;
|
|
||||||
|
IF :OLD.date_achat != :NEW.date_achat THEN
|
||||||
IF :OLD.reference != :NEW.reference THEN
|
modified_columns := modified_columns || 'date_achat, ';
|
||||||
SET modified_columns = CONCAT(modified_columns, 'reference, ');
|
END IF;
|
||||||
END IF;
|
|
||||||
|
IF :OLD.reference != :NEW.reference THEN
|
||||||
SET modified_columns = RTRIM(modified_columns, ', ');
|
modified_columns := modified_columns || 'reference, ';
|
||||||
|
END IF;
|
||||||
INSERT INTO CommandeAuditLog (Utilisateur, ActionSQL, DateMAJ, ActCol)
|
|
||||||
VALUES (USER, 'UPD', SYSDATE, modified_columns);
|
modified_columns := RTRIM(modified_columns, ', ');
|
||||||
|
|
||||||
|
INSERT INTO CommandeAuditLog (Utilisateur, ActionSQL, DateMAJ, ActCol)
|
||||||
|
VALUES (USER, 'UPD', SYSDATE, modified_columns);
|
||||||
|
END;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user