Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE Employee(
- emp_id VARCHAR2(20) NOT NULL PRIMARY KEY,
- name VARCHAR2(20),
- salary NUMBER(10),
- dept_no NUMBER(10)
- );
- ALTER TABLE EMPLOYEE ADD CONSTRAINT input CHECK(regexp_like(emp_id, '[A-Z][A-Z][A-Z]'));
- CREATE TABLE logEmp(
- emp_id VARCHAR2(20),
- change VARCHAR2(20),
- old_salary NUMBER(10),
- username VARCHAR2(20),
- change_date DATE
- );
- CREATE OR REPLACE TRIGGER Insertion AFTER INSERT ON Employee FOR each ROW
- BEGIN
- INSERT INTO logEmp VALUES(:NEW.emp_id, 'Insert', :old.salary, 'Shail', SYSDATE);
- END;
- /
- CREATE OR REPLACE TRIGGER Updation before UPDATE ON Employee FOR each ROW
- BEGIN
- INSERT INTO logEmp VALUES(:old.emp_id, 'Update', :old.salary, 'Shail', SYSDATE);
- END;
- /
- CREATE OR REPLACE TRIGGER Deletion before DELETE ON Employee FOR each ROW
- BEGIN
- INSERT INTO logEmp VALUES(:old.emp_id, 'Delete', :old.salary, 'Shail', SYSDATE);
- END;
- /
- INSERT INTO Employee VALUES('AAA', 'ABC XYZ', 4000, 12);
- UPDATE Employee SET salary = 5000 WHERE emp_id = 'AAA';
- DELETE FROM Employee WHERE emp_id = 'AAA';
- SELECT * FROM logEmp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement