--additional database check, to maintain database integrity

update weareremployment we
set    we.deliverypoint_id = (select min(dp.deliverypoint_id)
                               from   customer c, wearer w, deliverypoint dp
                               where  w.wearer_id = we.wearer_id
                               and    w.customer_id = c.customer_id
                               and    dp.customer_id = c.customer_id)
where  we.deliverypoint_id is null
and    we.locker_id is null
and    we.garmentdispenser_id is null;

commit;

update weareremployment we
set    we.deliverypoint_id = null
where  we.deliverypoint_id is not null
and    we.locker_id is not null;

commit;

update weareremployment we
set    we.deliverypoint_id = null
where  we.deliverypoint_id is not null
and    we.garmentdispenser_id is not null;

commit;

update weareremployment we
set    we.locker_id = null
where  we.locker_id is not null
and    we.garmentdispenser_id is not null;

commit;

alter table WEAREREMPLOYMENT
  add constraint CHK_WEAREREMPLOYMENT
  check ((deliverypoint_id  is not null and locker_id is null and garmentdispenser_id  is null)
  or (deliverypoint_id  is  null and locker_id is not null and garmentdispenser_id  is null)
  or (deliverypoint_id  is  null and locker_id is null and garmentdispenser_id  is not null));