- Get link
- X
- Other Apps
Create a trigger that checks if "value" is greater than 1000 for any new row inserted to "Test" table, then insert a row to Audit table?
- Get link
- X
- Other Apps
Program Code:-
DROP TABLE Test;
CREATE TABLE Test(test_id INTEGER,Name VARCHAR2(100),value NUMBER,test_date DATE);
DESC Test;
DROP TABLE Test_audit;
CREATE TABLE Test_audit(test_id INTEGER,Name VARCHAR2(100),value NUMBER,test_date DATE);
DESC Test_audit;
CREATE TRIGGER trg_test
AFTER INSERT OR UPDATE ON Test
FOR EACH ROW
BEGIN
IF :NEW.value > 1000 THEN
INSERT INTO Test_audit
VALUES(:NEW.test_id, :NEW.Name, :NEW.value, :NEW.test_date);
DBMS_OUTPUT.PUT_LINE('\n 1 ROW INSERTED TO TABLE TEST AUDIT');
END IF;
END trg_test;
INSERT INTO Test VALUES(103, 'DATABASE MANAGEMENT SYSTEM', 800, DATE '2021-04-15');
INSERT INTO Test VALUES(105, 'PROBABILITY AND STATISTICS', 1200, DATE '2021-04-16');
SELECT * FROM Test;
SELECT * FROM Test_audit;
Comments
Post a Comment