If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Create Database / Tables / Keys...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-12-07, 03:30
go4java go4java is offline
Registered User
 
Join Date: Jun 2007
Posts: 1
Create Database / Tables / Keys...

Hi,
I'm in the process of setting up a database with about 17000 horses.
Some of the attributes of a horse are (Sample):

...
foaled: 1999-03-23
died: n/a
sire: Madu Gold Dust
dam: SH Contessa
sire line: Skowronek (via Naseem)
dam line: Wadduda db (branch: Markada 1925)
strain: Saklawiyah Al Abd
...

As you can see, each horse (same as for humans) has ONE sire and ONE dam.
There will be a large tree structure up and down the sire / dam line.
Any horse may be selected in a web page (link) and all others should be retrieved from database and the tree structure should be build dynamically.

How to ideally set-up the tables and keys to quickly find mothers/fathers as well as childs up and down the line?

Best regards
Reply With Quote
  #2 (permalink)  
Old 06-12-07, 05:30
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
a horse has details relevant to that horse
a horse has two parents
a horse may compete in many races
a horse racing event may have many races
a horse racing arena may hold many events
a series may comprise many events from many or one arena over a period of time
a horse may change its name over time
a horse may have many owners over time

a horse may have many riders over time, but only one rider per race
a horse may have many trainers over time, but only one trainer at anyone time

so for your horse table you may see somehting like
HorseID autonumber PK
HorseName
OwnedBy bigint 'fk to table containing details of owners
HorseType 'identifies the type of horse could be M/F, or could be fill, stallion, gelding orwhatever silly names horsey people give
Mare 'fk to to the mare of this horse to another row in this table
Sire 'fk to to the sire of this horse to another row in this table
DoB 'date of the horse's birth
....etc


..you would need to iterate up or down the tree using a series of SQL calls

one problem you are going to have is recursion and re-entry. its quite feasible for the same sire line to re-appear in the progeny, especailly as AI is increasingly used.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 06-12-07, 07:28
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by go4java
How to ideally set-up the tables and keys to quickly find mothers/fathers as well as childs up and down the line?
use the nested set data model
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 06-13-07, 03:23
abhijeetclarion abhijeetclarion is offline
Registered User
 
Join Date: May 2007
Posts: 5
Cool

Here is an good article with examples on Hierarchical data

http://dev.mysql.com/tech-resources/...ical-data.html
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On