Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
826 B
2
Indexable
CREATE TABLE STUDENTS (
    student_id INT PRIMARY KEY,
    name VARCHAR(100),
    age INT,
    enrollment_date DATE
);
CREATE TABLE EMP_LOG (
    log_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    student_id INT,
    action VARCHAR2(10),
    action_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    old_value VARCHAR2(255),
    new_value VARCHAR2(255)
);
CREATE OR REPLACE TRIGGER after_student_insert
AFTER INSERT ON STUDENTS
FOR EACH ROW
BEGIN
    INSERT INTO EMP_LOG (student_id, action, new_value)
    VALUES (:NEW.student_id, 'INSERT', 
            'Name: ' || :NEW.name || ', Age: ' || :NEW.age || ', Enrollment Date: ' || :NEW.enrollment_date);
END;
/
INSERT INTO STUDENTS (student_id, name, age, enrollment_date)
VALUES (1, 'Yubaraj Karki', 20, TO_DATE('2024-08-01', 'YYYY-MM-DD'));
Leave a Comment