/*****************************************************************************
*
* Filename         - $Workfile:   bag_triggers.sql  $
*
*                     Name              Date      Version     CR Number
* Author           - See revision history below.
* Last Update      - See revision history below.
*
* Project Name     - TAGTRAK(Oracle database)
*
* Source Code
* Identifier       - 0/3/300/8010/112
*
* Design Spec
* Section          - 
*
* Contents         - Archive schema triggers for bag table.
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   bag_triggers.sql  $  $Revision:   1.3  $
*
* Revision History
*
* Note that user tagtrak is many users. For these users the user
* name is entered as the last line in the change description.
*
* $Log:   /shared/pvcs/tagtarch/db_ora/db/source/arch/triggers/bag_triggers.sqv  $
* 
*    Rev 1.3   02 Apr 1998 19:07:28   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.2   28 Oct 1997 14:12:40   tagtrak
* Added PVCS header
*
****************************************************************************/


create or replace trigger tu_bag
before update on bag
begin
	no_archive_modify;
end;
/
create or replace trigger ti_bag
before insert on bag
for each row
declare
 numrows integer;
begin
    
 if (:new.delete_marker = 0) then
   /* check tables pk */
   select count(*)
   into numrows
   from bag
   where pax_id = :new.pax_id
   and bag_tag3 = :new.bag_tag3
   and bag_tag2b = :new.bag_tag2b
   and bag_tag2a = :new.bag_tag2a
   and bag_tag1 = :new.bag_tag1
   and delete_marker = 0;
  
   if (numrows > 0) then
		raise_application_error( -20027, 'Attempt to insert a Duplicate Value into Unique Key' );
   end if;
end if;
end;
/

create or replace trigger td_bag
before delete on bag
for each row
begin
 
	delete from
		bag_alert
	where
		pax_id = :old.pax_id and
		bag_tag2b = :old.bag_tag2b and
		bag_tag3 = :old.bag_tag3;

	delete from misc_bag_exceptions where bag_id = :old.bag_id;

end;
/
