/*
  Illustrates the firing of a trigger for
	the insertion of a customer row with a non-existing repnum value.
  Replace "FOR" with "INSTEAD OF" and
	observe the integrity constraint executions

  --Prabakar 3/3/08
*/
create trigger RepCheck
on Customer
FOR insert as -- use (either "FOR" or "AFTER") or "INSTEAD OF"

-- body of the trigger
if not exists
	(select RepNum
	 from inserted -- newly inserted row
	 where RepNum IN
	  ( select RepNum from Rep))
 Begin
  print('Invalid Rep Number')
  Rollback -- undo the new insertion
 End
