2 Replies - 472 Views - Last Post: 14 March 2011 - 03:14 PM Rate Topic: -----

#1 jsutton  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 17-March 10

Using a table column twice as compound foreign key

Posted 14 March 2011 - 07:47 AM

Hi,

I have a database holding family tree data.
I have a table called person, with all relevent details about them personally (name, date of birth, birthplace, gender)

I need some way of managing relationships bewteen the people in my database. I would like to have another table made of a compound foreign key, with two personID's from the person table.

Is this possible? or are there any obvious workarounds?
I will be implementing the database using hsqldb.

Thanks in advance
Joe Sutton

Is This A Good Question/Topic? 0
  • +

Replies To: Using a table column twice as compound foreign key

#2 AdaHacker  Icon User is online

  • Resident Curmudgeon

Reputation: 433
  • Posts: 789
  • Joined: 17-June 08

Re: Using a table column twice as compound foreign key

Posted 14 March 2011 - 02:45 PM

By definition, a compound key consists of two or more columns. The idea of having a "compound" key that uses the same column twice doesn't make sense. What would that even mean in terms of enforcing the constraint?

Fortunately, it sounds like what you're looking for isn't a single compound key, but two different foreign keys that both reference the same column. There should be no problem with doing that.
Was This Post Helpful? 0
  • +
  • -

#3 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,053
  • Joined: 17-July 10

Re: Using a table column twice as compound foreign key

Posted 14 March 2011 - 03:14 PM

Another table with parentID and ChildID, both referencing Person should be enough to accomplish what you want. A column can be referenced by any number of tables. Just make sure to put a constraint or something(I don't know about hsqldb) to avoid having the same id on parentId column and ChildId column
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1