Home > AS/400 Tips > iSeries administrator tips > Must-knows when using referential constraints and triggers together
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES ADMINISTRATOR TIPS

Must-knows when using referential constraints and triggers together


Ron Turull
03.14.2006
Rating: -3.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



Ron Turull
Before you add triggers and referential constraints to the same file, there are a few caveats of which you should be aware. The two can be used on the same file. They may complement each other, or they may perform mutually exclusive tasks. Regardless of the design, you should keep the following points in mind.

More Information

1. There is a distinct order in which the system calls triggers and evaluates referential constraints. The order is (from first to last):

  • Before triggers


  • Restrict referential constraints


  • After triggers


  • No-action, cascade, set-default , and set-null constraints


  • That is extremely important if a trigger works in conjunction with a referential constraint. For example, you design a trigger to insert a new parent file record, if needed, when a new dependent file record is inserted. Because there is an implied insert restrict constraint on the files (added the first time you add any constraint), the trigger program must be a before insert trigger so it will be called before the insert restrict constraint is checked.

    2. You cannot add a delete trigger to a file that is a dependent file in a delete cascade referential constraint relationship.

    IBM's reasoning behind that is to avoid a situation where thousands of dependent records are being deleted as a result of the delete cascade constraint and, for each one, delete triggers must be called. The system could come to a grinding halt if it took place in a high-priority job (i.e., interactive job). Unfortunately, there may be times when you want both functions and are willing to accept the consequences. One can only hope that IBM will remove that limitation in a future release.

    Circumvention:

    In the meantime, to get around that restriction you can put the delete triggers on the parent file if the design will support it. Otherwise, you can implement the delete cascade constraint using another trigger (we'll discuss how to do that and see an example in the next few installments of this column).

    3. You cannot add an update trigger to a file that is a dependent file in a delete set-null or a delete set-default referential constraint relationship.

    The reasoning behind that is similar to the previous item (i.e., delete set-null and delete set-default constraints have the potential of updating many records in a dependent file). Again, a possible work-around is to implement the constraint using a trigger.

    -----------------------------------
    About the author: Ron Turull is editor of Inside Version 5. He has more than 20 years' experience programming for and managing AS/400-iSeries systems.


    Rate this Tip
    To rate tips, you must be a member of Search400.com.
    Register now to start rating these tips. Log in if you are already a member.


    Submit a Tip




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



    RELATED CONTENT
    iSeries administrator tips
    Analyze the health of your IBM i server with iScore
    Researching high availability for your System i shop
    Translating Linux for IBM i admins: Using GUI to make it easy
    Translating Linux for IBM i admins: Working with jobs and networking
    OpenOffice: What to know before making the transition from Microsoft Office
    OpenOffice: An enterprise open source solution
    Database performance comparisons on IBM i
    Translating Linux for IBM i admins: User profile commands
    Modern System i reports using Client Access
    Tips for installing Lotus Domino server on a System i partition

    iSeries Applications
    Modern System i reports using Client Access
    Tips for installing Lotus Domino server on a System i partition
    Documenting nested program structures on the AS/400
    System i no longer the stepchild of IBM's world
    Storing XML data in a CLOB field
    IBM System i gets VoIP via Nortel
    Top 10 System i white papers
    Fast Guide to System i/iSeries book excerpts
    Top System i admin tips for 2006
    System i software wrap
    iSeries Applications Research

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



    iSeries Security - Security Tools, Physical Security and System Security
    HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts