Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2009
    Posts
    6

    Unanswered: Referential Constraint on nickname (federated object)

    Hi everyone,

    Is it possible to define a referential constraint using a nickname (federated database table)?

    I'm getting the following error:
    The nickname "NBM" cannot be referenced in an enforced referential constraint.. SQLCODE=-20269, SQLSTATE= , DRIVER=4.8.86

    Does anybody know other ways to enforce a referenctial integrity on a local table using nickname (remote federated table)?

    Thank you for help.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Try creating a view over the nickname.

  3. #3
    Join Date
    Oct 2009
    Posts
    6
    Thanks for the reply, n_i.
    I though that it not possible to create a foreign key constraint to a view? Am I wrong here? Anyway I tried creating a view over the nickname and have a foreign key reference to this view. It gives the following error:
    "TST.V_TEST" is not allowed in a FOREIGN KEY clause because it does not identify a base table.. SQLCODE=-157, SQLSTATE=42810, DRIVER=4.8.86

    It would be if somebody can shed some light on it.

  4. #4
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    A nickname is just a pointer to a table in some other system. If that remote table is the dependent table, nothing will prevent that other system from inserting a row that would violate the FK. If the remote table would be the parent in a referential constraint, nothing would prevent the other system from removing rows that are needed by local dependent tables. So what's the point of the FK if the system has no chance to enforce it? None.

    Using a view as Nick suggested would provide you the capability to query the view and detect inconsistencies yourself (and resolve them somehow) or going the other direction, joining the parent and dependent table in the view so that the view guarantees you'll only see consistent data.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  5. #5
    Join Date
    Oct 2009
    Posts
    6
    stolze, thanks for the reply.

    yes, I understand that a nickname is just a pointer to a remote object.
    What I was wondering if there are any other options/workarounds on how to enforce the referential integrity (again by using DB2 itselft and not using views/stored procedures for manual checking) between the local (child) and remote (parent) tables. I'd like to avoid using triggers as they introduce an extra overhead on the processing.

    here is the scenario:
    database A has a "child" table CHD (with column ref_col_id)
    database B has a "parent" table PRT (with column ref_col_id)
    An application inserts data into A.CHD. I want to make sure that only records with ref_col_id values that are present in B.PRT are inserted.
    The only way to enforce referential integrity by using constraints is to create a mirror copy of B.PRT in database A and reference A.CHD to it.
    This brings other issues of storing the data twice and making sure that both A.PRT and B.PRT are always in sync.

    I just want to make sure that there is no way to use constraints in this case and the only option is to go with either views/triggers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •