Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 To: Anti-cursor prophets (self-recursive tables)

Author  Topic 

alebey
Starting Member

17 Posts

Posted - 2001-08-15 : 20:50:18
Imagine a database table with the following structure:


.-> YakID (unique key)
| YakName
| FurColor
| Height
| Weight
*-- MotherYakID
*-- FatherYakID


That is: store information about a particular yak, but also store a reference to both parents of this yak. Very reasonable and consise structure, isn't it?

Now, how would I come up with a (cursor-less!) stored procedure that would return a recordset with the information about this yak, plus the names of both of its parents? Something along the lines of:

YakID | YakName | FurColor | Height | Weight | MotherName | FatherName


Easy right? What about the above plus the names of four of the grandparents? Of eight of the great-grandparents?

How would I go about capturing the entire branch (up to the root) of the family tree, without knowing how many generations of yaks I have?

Patienly waiting for possible solutions.


   

- Advertisement -