dbTalk Databases Forums  

Enity problem

comp.databases comp.databases


Discuss Enity problem in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
dnomade@gmail.com
 
Posts: n/a

Default Enity problem - 05-05-2007 , 09:30 AM






Hi all!

I am trying to create an database for relation between parents and
their children. I started with these Entities:

Parent
Child
Parent_Child (parent_id fk, child_id fk)

But this will only show relation between one parent and one child, so
I thought I could set up the Entity Parents to manifest the relation
between 2 parents. It's here my theory gets little rusty.

When I model this I struggle to see that it's correct

Parents Entity (Example):
parents_id (PK)
parent_id (FK)
parent_id (FK)

The second problem I struggle with is that a parent could have
children with more than one other parent. This I don't quite get a
grip of.

So if somebody have some pointers for I will appreciate it


Reply With Quote
  #2  
Old   
Jerry Gitomer
 
Posts: n/a

Default Re: Enity problem - 05-05-2007 , 10:33 AM






On Sat, 05 May 2007 06:30:05 -0700, dnomade wrote:

Quote:
Hi all!

I am trying to create an database for relation between parents and their
children. I started with these Entities:

Parent
Child
Parent_Child (parent_id fk, child_id fk)

But this will only show relation between one parent and one child, so I
thought I could set up the Entity Parents to manifest the relation between
2 parents. It's here my theory gets little rusty.

When I model this I struggle to see that it's correct

Parents Entity (Example):
parents_id (PK)
parent_id (FK)
parent_id (FK)

The second problem I struggle with is that a parent could have children
with more than one other parent. This I don't quite get a grip of.

So if somebody have some pointers for I will appreciate it
Your initial table set-up, with one minor change, will suffice.

The change is to use as the primary key for your Parent-Child table the
combination of parent-id and child-id. This will permit you to quickly
access all of the children of any parent. (If you are using an RDBMS
that doesn't require tables to have primary keys -- no changes are required.)

This will also solve your second problem -- but retrieval will be
slow since the entire Parent-Child table will have to be searched to find
all of the parents of a child. If performance is an issue you can add a
secondary index on child-id.

HTH
Jerry-the-bookkeeper





Reply With Quote
  #3  
Old   
dNomade
 
Posts: n/a

Default Re: Enity problem - 05-05-2007 , 05:10 PM



On 5 Mai, 16:33, Jerry Gitomer <jgito... (AT) verizon (DOT) net> wrote:
Quote:
On Sat, 05 May 2007 06:30:05 -0700, dnomade wrote:
Hi all!

I am trying to create an database for relation between parents and their
children. I started with these Entities:

Parent
Child
Parent_Child (parent_id fk, child_id fk)

But this will only show relation between one parent and one child, so I
thought I could set up the Entity Parents to manifest the relation between
2 parents. It's here my theory gets little rusty.

When I model this I struggle to see that it's correct

Parents Entity (Example):
parents_id (PK)
parent_id (FK)
parent_id (FK)

The second problem I struggle with is that a parent could have children
with more than one other parent. This I don't quite get a grip of.

So if somebody have some pointers for I will appreciate it

Your initial table set-up, with one minor change, will suffice.

The change is to use as the primary key for your Parent-Child table the
combination of parent-id and child-id. This will permit you to quickly
access all of the children of any parent. (If you are using an RDBMS
that doesn't require tables to have primary keys -- no changes are required.)

This will also solve your second problem -- but retrieval will be
slow since the entire Parent-Child table will have to be searched to find
all of the parents of a child. If performance is an issue you can add a
secondary index on child-id.

HTH
Jerry-the-bookkeeper
Thank you for your response

I will see into the suggestion.

Thank you again

David



Reply With Quote
  #4  
Old   
David Cressey
 
Posts: n/a

Default Re: Enity problem - 05-05-2007 , 05:26 PM




<dnomade (AT) gmail (DOT) com> wrote

Quote:
Hi all!

I am trying to create an database for relation between parents and
their children. I started with these Entities:

Parent
Child
Parent_Child (parent_id fk, child_id fk)

But this will only show relation between one parent and one child, so
I thought I could set up the Entity Parents to manifest the relation
between 2 parents. It's here my theory gets little rusty.

When I model this I struggle to see that it's correct

Parents Entity (Example):
parents_id (PK)
parent_id (FK)
parent_id (FK)

The second problem I struggle with is that a parent could have
children with more than one other parent. This I don't quite get a
grip of.

So if somebody have some pointers for I will appreciate it

First off, should you have an entity called "persons"? Can't a person be a
parent and also a child (of a different person, of course).





Reply With Quote
  #5  
Old   
dNomade
 
Posts: n/a

Default Re: Enity problem - 05-07-2007 , 01:24 PM



On May 5, 11:26 pm, "David Cressey" <cresse... (AT) verizon (DOT) net> wrote:
Quote:
dnom... (AT) gmail (DOT) com> wrote in message

news:1178371805.871661.147370 (AT) h2g2000hsg (DOT) googlegroups.com...



Hi all!

I am trying to create an database for relation between parents and
their children. I started with these Entities:

Parent
Child
Parent_Child (parent_id fk, child_id fk)

But this will only show relation between one parent and one child, so
I thought I could set up the Entity Parents to manifest the relation
between 2 parents. It's here my theory gets little rusty.

When I model this I struggle to see that it's correct

Parents Entity (Example):
parents_id (PK)
parent_id (FK)
parent_id (FK)

The second problem I struggle with is that a parent could have
children with more than one other parent. This I don't quite get a
grip of.

So if somebody have some pointers for I will appreciate it

First off, should you have an entity called "persons"? Can't a person be a
parent and also a child (of a different person, of course).

David Cressey:
How will this help?

I can't see that this will help to fin the relation between a parent
and the other parents he/she has children with. Could you please
explain it for me please

Thanks in advanced
David



Reply With Quote
  #6  
Old   
strawberry
 
Posts: n/a

Default Re: Enity problem - 05-07-2007 , 02:54 PM



On May 7, 6:24 pm, dNomade <dnom... (AT) gmail (DOT) com> wrote:
Quote:
On May 5, 11:26 pm, "David Cressey" <cresse... (AT) verizon (DOT) net> wrote:



dnom... (AT) gmail (DOT) com> wrote in message

news:1178371805.871661.147370 (AT) h2g2000hsg (DOT) googlegroups.com...

Hi all!

I am trying to create an database for relation between parents and
their children. I started with these Entities:

Parent
Child
Parent_Child (parent_id fk, child_id fk)

But this will only show relation between one parent and one child, so
I thought I could set up the Entity Parents to manifest the relation
between 2 parents. It's here my theory gets little rusty.

When I model this I struggle to see that it's correct

Parents Entity (Example):
parents_id (PK)
parent_id (FK)
parent_id (FK)

The second problem I struggle with is that a parent could have
children with more than one other parent. This I don't quite get a
grip of.

So if somebody have some pointers for I will appreciate it

First off, should you have an entity called "persons"? Can't a person be a
parent and also a child (of a different person, of course).

David Cressey:
How will this help?

I can't see that this will help to fin the relation between a parent
and the other parents he/she has children with. Could you please
explain it for me please

Thanks in advanced
David

To clarify, in its simplest form you could use a structure like this:

relationships(name*,parent*)
* = (compound) PRIMARY KEY

To obtain a list of all the people with whom a given individual has co-
authored children:

SELECT r2.* FROM relationships r1
JOIN relationships r2 ON r2.name = r1.name
WHERE r1.parent = 'john lennon'
AND r2.parent <> 'john lennon';

result:

name________parent
julian lennon__cynthia lennon
sean lennon__yoko ono lennon



Reply With Quote
  #7  
Old   
Last Boy Scout
 
Posts: n/a

Default Re: Enity problem - 05-14-2007 , 10:24 PM



dnomade (AT) gmail (DOT) com wrote:
Quote:
Hi all!

I am trying to create an database for relation between parents and
their children. I started with these Entities:

Parent
Child
Parent_Child (parent_id fk, child_id fk)

But this will only show relation between one parent and one child, so
I thought I could set up the Entity Parents to manifest the relation
between 2 parents. It's here my theory gets little rusty.

When I model this I struggle to see that it's correct

Parents Entity (Example):
parents_id (PK)
parent_id (FK)
parent_id (FK)

The second problem I struggle with is that a parent could have
children with more than one other parent. This I don't quite get a
grip of.

So if somebody have some pointers for I will appreciate it

A child can only have 2 Birth parents, a mother and a father. You have
to decide what kind of business rules you are going to have in these
relationships. However, in this day and age many things are confused.
Even in Genealogy a person can only have 2 parents. Adults however can
have many children with sometimes with a legal spouse and sometimes with
multiple partners not married. When you think of a birth certificate,
you have to look at the elements on the certificate; Location, Date,
time, Father Mother.

People are born
People may be married
People have Parents
People have children

These kind of relationships can be very complicated.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.