Results 1 to 9 of 9

Thread: 1:1 relationships - SQL Anywhere

  1. #1
    Join Date
    Jun 2005
    Posts
    11

    1:1 relationships - SQL Anywhere

    Hi All,

    How are 1:1 relationships represented in relational models? Do both sides get a foreign key?

    Many thanks,
    Barry

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    No, only one has foreign key (the referencing table). It also needs to have to unique key defined to enforce uniqueness.

  3. #3
    Join Date
    Jun 2005
    Posts
    11
    Ok. So what about implementation - is there still only one side that 'knows' about the relationship?

  4. #4
    Join Date
    Sep 2002
    Posts
    5,938
    Put pkey on parent table and fkey on child table, they both know.

  5. #5
    Join Date
    Jun 2005
    Posts
    11
    Moving back to the realational model, what if the 1:1 was mandatory on both sides. Does this make any difference?

  6. #6
    Join Date
    Sep 2002
    Posts
    5,938
    Then put unique constraint on fkey column on child table.

  7. #7
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    No make it mandatory you have to make it NOT NULL in child table, and primary key on parent table will prevent NULL value anyway.

  8. #8
    Join Date
    Jun 2005
    Posts
    11
    i've got to be honest, you're using more advanced terminology than I'm used to. To me, parent and child means supertype and subtype, yet I haven't mentioned this arrangement at all.

  9. #9
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Supertype and subtype are not exactly same as parent and child, but related. Supertype/subtype is logical concept and parent/child is physical implementation concept. Let me give you an example.

    If you have a table called Person with information such as names, etc. and Employee table as subtype with employee specific information. Then Parent is supertype and employee is subtype. To enforce this relation, you create a foreign key in Employee table to reference corresponding record in person table. Now Person is parent table and Employee is child table.

Posting Permissions

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