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)
|
||||
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;
|
||||
|
||||
|
||||
@ -119,7 +145,7 @@ CREATE TABLE ligne_commande (
|
||||
produit_id INT,
|
||||
quantite INT,
|
||||
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 (
|
||||
Utilisateur VARCHAR(50),
|
||||
ActionSQL VARCHAR(3), -- 'INS', 'DEL', ou 'UPD'
|
||||
ActionSQL VARCHAR(3),
|
||||
DateMAJ DATE DEFAULT SYSDATE,
|
||||
ActCol VARCHAR(255)
|
||||
);
|
||||
|
||||
CREATE TRIGGER trg_AuditInsertCommande
|
||||
CREATE OR REPLACE TRIGGER trg_AuditInsertCommande
|
||||
AFTER INSERT ON Commande
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
@ -140,7 +166,7 @@ BEGIN
|
||||
VALUES (USER, 'INS', SYSDATE, 'N/A');
|
||||
END;
|
||||
|
||||
CREATE TRIGGER trg_AuditDeleteCommande
|
||||
CREATE OR REPLACE TRIGGER trg_AuditDeleteCommande
|
||||
AFTER DELETE ON Commande
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
@ -148,24 +174,30 @@ BEGIN
|
||||
VALUES (USER, 'DEL', SYSDATE, 'N/A');
|
||||
END;
|
||||
|
||||
CREATE TRIGGER trg_AuditUpdateCommande
|
||||
AFTER UPDATE ON Commande
|
||||
CREATE OR REPLACE TRIGGER trg_AfterUpdateCommande3
|
||||
AFTER UPDATE ON Commande3
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE modified_columns VARCHAR(255);
|
||||
|
||||
SET modified_columns = '';
|
||||
|
||||
IF :OLD.date_achat != :NEW.date_achat THEN
|
||||
SET modified_columns = CONCAT(modified_columns, 'date_achat, ');
|
||||
END IF;
|
||||
|
||||
IF :OLD.reference != :NEW.reference THEN
|
||||
SET modified_columns = CONCAT(modified_columns, 'reference, ');
|
||||
END IF;
|
||||
|
||||
SET modified_columns = RTRIM(modified_columns, ', ');
|
||||
|
||||
INSERT INTO CommandeAuditLog (Utilisateur, ActionSQL, DateMAJ, ActCol)
|
||||
VALUES (USER, 'UPD', SYSDATE, modified_columns);
|
||||
|
||||
DECLARE
|
||||
modified_columns VARCHAR2(255);
|
||||
BEGIN
|
||||
|
||||
modified_columns := '';
|
||||
|
||||
IF :OLD.date_achat != :NEW.date_achat THEN
|
||||
modified_columns := modified_columns || 'date_achat, ';
|
||||
END IF;
|
||||
|
||||
IF :OLD.reference != :NEW.reference THEN
|
||||
modified_columns := modified_columns || 'reference, ';
|
||||
END IF;
|
||||
|
||||
modified_columns := RTRIM(modified_columns, ', ');
|
||||
|
||||
INSERT INTO CommandeAuditLog (Utilisateur, ActionSQL, DateMAJ, ActCol)
|
||||
VALUES (USER, 'UPD', SYSDATE, modified_columns);
|
||||
END;
|
||||
END;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user