ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

TRIGGERS ON VIEWS - (Known as "INSTEAD OF" Triggers") What Causes them to fire?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TRIGGERS ON VIEWS - (Known as "INSTEAD OF" Triggers") What Causes them to fire?

    I Searched the DB2 Forum and did not find anything about this before posting this question.
    I am looking for confirmation that TRIGGERS placed on VIEWS only fire when you use the view and not the underlying File/Table.

    Here is and example. PF/TABLE named DTLTRAN and VIEW of that table name VWDTLTRAN.
    the TRIGGERS, one for insert and one for Update are placed on VWDTLTRAN.

    If I do an insert/update on DTLTRAN the triggers DO NOT fire. (is this the correct behavior? or should they be firing. We hoped they would. )
    If I do an insert/update on VWDTLTRAN the triggers DO fire. (is this the correct behavior?)

    While I have read a lot of IBM documentation. (I did get it to work) That documentation never explicitly said "The Triggers on VIEWS Fire When....."

    Thanks for your help.
    Last edited by DavidLerman; October 5, 2016, 08:15 AM.

  • #2
    Both of the behaviors are correct. If modifying a base TABLE caused an INSTEAD OF trigger to fire on a VIEW, an infinite loop might result as the INSTEAD OF trigger issued its modifying instructions back to the base TABLE.

    It gets difficult to list things that do not cause behaviors because the list would get excessively long. But I can see why you can't find an explicit statement such as "The Triggers on VIEWS Fire When...". I did a little looking and also found no such explicit statement (only a little looking). However, documentation did come across to me as strongly implying the noted behaviors. And deeper searches by others might find what you're looking for.
    Tom

    There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

    Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

    Comment


    • #3
      Extract from the SQL Reference:
      The associated triggered action replaces the action against the subject view. Only one INSTEAD OF trigger is allowed for each kind of operation on a given subject view. The database manager executes the triggered-action instead of the insert, delete, or update operation on the subject view.

      Birgitta
      Last edited by B.Hauser; October 5, 2016, 11:21 PM.

      Comment


      • #4
        Originally posted by B.Hauser View Post
        Extract from the SQL Reference:
        Yes, but does it say anywhere that updating the base table does not cause the INSTEAD OF trigger to fire? Not that I can tell, but I wouldn't expect it say that. The OP is apparently looking for an explicit statement (about the base table of the view).
        Tom

        There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

        Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

        Comment


        • #5
          TomLiotta and B. Hauser Thank you for responding. I think "The database manager executes the triggered-action instead of the insert, delete, or update operation on the subject view." Says it all. I actually remember reading that passage now.
          Please consider this a closed inquiry. I am moving on to "RCVJRNE to an exit program" solution. (Gosh, I hope I can manage this one without coming back to Code400 for help..)

          Comment

          Working...
          X