----------------------------------------------------------------------
-- Clean up from last try.
----------------------------------------------------------------------

drop trigger CheckEmployeeTrigger on Payroll;
drop function CheckEmployeeFunc();
drop table Payroll;


----------------------------------------------------------------------
-- Create new schema.
----------------------------------------------------------------------

create table Payroll
(
   Id     integer,
   Name   varchar(30),
   SId    integer,
   Salary integer,
   primary key (Id)
);

create function CheckEmployeeFunc() returns trigger as $$
declare


begin


end;
$$ language 'plpgsql';

create trigger CheckEmployeeTrigger before insert or update on Payroll
for each row execute procedure CheckEmployeeFunc();


----------------------------------------------------------------------
-- Run a test suite.
----------------------------------------------------------------------

insert into payroll values (2, 'Tom', NULL, 75000);

insert into payroll values (3, 'Justin', NULL, 75000);

insert into payroll values (1, 'Jill', NULL, 100000);

update payroll set sid = 1 where id = 2;
update payroll set sid = 1 where id = 3;

update payroll set salary = 150000 where id = 3;

select * from payroll;

update payroll set salary = 200000 where id = 1;

select * from payroll;
