source: database/Advanced Database Developement/Triggers/Automatic update of employee-store statistics after an employee is hired.txt@ 62b2964

finki-main main
Last change on this file since 62b2964 was 62b2964, checked in by Klimentina Efremova <klimentina08642@…>, 2 weeks ago

Project Handcraft Marketplace

  • Property mode set to 100644
File size: 646 bytes
Line 
1CREATE OR REPLACE FUNCTION initialize_employee_statistics()
2RETURNS TRIGGER
3LANGUAGE plpgsql
4AS $$
5BEGIN
6 /*
7 * The employee is created first.
8 * Work statistics can be initialized when
9 * the employee is assigned to a store.
10 * The actual store assignment should be handled
11 * through works_in_store. */
12 INSERT INTO worked (
13 employee_id,
14 total_working_hours,
15 total_wage
16 )
17 VALUES (
18 NEW.id,
19 0,
20 0
21 );
22 RETURN NEW;
23END;
24$$;
25
26CREATE TRIGGER trg_initialize_employee_statistics
27AFTER INSERT
28ON employees
29FOR EACH ROW
30EXECUTE FUNCTION initialize_employee_statistics();
Note: See TracBrowser for help on using the repository browser.