Advertisement
Shailrshah

Log of Changes made in the Employee Table

Oct 28th, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.22 KB | None | 0 0
  1. CREATE TABLE Employee(
  2.     emp_id                  VARCHAR2(20)    NOT NULL PRIMARY KEY,
  3.     name                    VARCHAR2(20),
  4.     salary                  NUMBER(10),
  5.     dept_no                 NUMBER(10)
  6. );
  7. ALTER TABLE EMPLOYEE ADD CONSTRAINT input CHECK(regexp_like(emp_id, '[A-Z][A-Z][A-Z]'));
  8. CREATE TABLE logEmp(
  9.     emp_id                  VARCHAR2(20),
  10.     change                  VARCHAR2(20),
  11.     old_salary              NUMBER(10),
  12.     username                VARCHAR2(20),
  13.     change_date             DATE
  14. );
  15. CREATE OR REPLACE TRIGGER Insertion AFTER INSERT ON Employee FOR each ROW
  16. BEGIN
  17.     INSERT INTO logEmp VALUES(:NEW.emp_id, 'Insert', :old.salary, 'Shail', SYSDATE);
  18. END;
  19. /
  20. CREATE OR REPLACE TRIGGER Updation before UPDATE ON Employee FOR each ROW
  21. BEGIN
  22.     INSERT INTO logEmp VALUES(:old.emp_id, 'Update', :old.salary, 'Shail', SYSDATE);
  23. END;
  24. /
  25. CREATE OR REPLACE TRIGGER Deletion before DELETE ON Employee FOR each ROW
  26. BEGIN
  27.     INSERT INTO logEmp VALUES(:old.emp_id, 'Delete', :old.salary, 'Shail', SYSDATE);
  28. END;
  29. /
  30. INSERT INTO Employee VALUES('AAA', 'ABC XYZ', 4000, 12);
  31. UPDATE Employee SET salary = 5000 WHERE emp_id = 'AAA';
  32. DELETE FROM Employee WHERE emp_id = 'AAA';
  33. SELECT * FROM logEmp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement