SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE employee_history( operation_id serial, operation_type text, operation_time timestamp, operation_user text, new_name text, new_salary text ); CREATE OR REPLACE FUNCTION employee_change_history_row() RETURNS TRIGGER AS $$ BEGIN INSERT INTO employee_history(operation_type, operation_time, operation_user, new_name, new_salary) VALUES (TG_OP, current_timestamp, current_user, NEW.name, NEW.salary); RETURN NEW; END $$ LANGUAGE 'plpgsql'; CREATE OR REPLACE TRIGGER employee_change_history_trigger BEFORE INSERT OR UPDATE ON employee FOR EACH ROW EXECUTE FUNCTION employee_change_history_row(); INSERT INTO employee(name, salary) VALUES('Katara', 20); UPDATE employee SET salary = salary + 100 WHERE name = 'Katara' OR name = 'Aang'; UPDATE employee SET salary = 0 WHERE name = 'Zuko'; SELECT * FROM employee_history;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear