Results 1 to 4 of 4
  1. #1
    odeno is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default creating many-many relationships in javadb

    Hi,

    I need to create some many-many relationships between two tables and want to use a link table to do this.

    It is rather simple and standard but can't figure out how to do this in javadb.

    tab1
    pk1
    ..
    ..

    tab2
    pk2
    ....

    tab1_tab2
    pf_k1
    pf_k2
    /* the above represent a compound primary key */

    How on earth do I create the above in javadb / derbydb?

    I've tried the following:-

    Alter table tab1 add constraint tab1_fk foreign key (pk1) references tab1_tab2 (pf_k1)

    and likewise for tab2 and pk2 but I get the following error:-

    "Error code -1, SQL state X0Y44: Constraint 'TAB1_FK' is invalid: there is no unique or primary key constraint on table '"APP"."DEL_SEM"' that matches the number and types of the columns in the foreign key."

    I've tried so many combinations and searched and searched the web to no avail. Hoping someone here can help.....

    thanks,

  2. #2
    odeno is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    sorry the error is:-


    "Error code -1, SQL state X0Y44: Constraint 'TAB1_FK' is invalid: there is no unique or primary key constraint on table "tab1_tab2"' that matches the number and types of the columns in the foreign key."

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    pf_k1 needes to be defined as a prmary key or as a unique constraint (which is exactly what that exception says) before you can reference it as a foreign key.

  4. #4
    odeno is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    thanks - yes had realised this and solved it.

    thanks againfor replying....

Similar Threads

  1. Creating files stopped creating...
    By Dieter in forum Advanced Java
    Replies: 3
    Last Post: 09-25-2009, 11:45 PM
  2. Need help creating a table
    By Knizz in forum SWT / JFace
    Replies: 3
    Last Post: 07-18-2009, 03:46 AM
  3. load driver in javaDB
    By kulangotski in forum New To Java
    Replies: 1
    Last Post: 02-20-2009, 07:15 PM
  4. JavaDB Help
    By Sysem in forum New To Java
    Replies: 5
    Last Post: 05-29-2008, 09:21 PM
  5. JavaDB Installation
    By PhilArmstrong in forum New To Java
    Replies: 6
    Last Post: 05-13-2008, 02:09 PM

Posting Permissions

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