By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,378 Members | 1,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,378 IT Pros & Developers. It's quick & easy.

Sql

P: 92
Can anyone suggest me for this, i was just confused whether i can create 3 separate table or i can simplify this table.

My question is

i wnt to create a treeview to display some values
so that i m hving the table as

1.For ParentTable
ParentID
ParentName

2.For ChildTable
ParentID
ChildID
ChildName

3.SubChildTable
ChildID
GrandChildName

i wnt to display data based on its ID like

ParentName
---ChildName
------GrandChildName1
------GrandChildName2
---ChildName1

goes on

is any possibility to simplify this Tables.
if soo, it'll give some repeated values

i dont know wht ll i do.
Help Me please
Thanks in Advance
May 2 '08 #1
Share this Question
Share on Google+
3 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Example:

John is the Grandfather - his son is Peter. Peter is the father to Bill.

Relationship is John - Peter - Bill. In a database you only need one table to represent this.

tblPerson
PersonID (Primary key)
PersonName
ChildID (Foreign key referencing the primary key of its own table)

Data:

PersonID PersonName ChildID
1 John 2
2 Peter 3
3 Bill

Expand|Select|Wrap|Line Numbers
  1. SELECT T1.PersonID, T1.PersonName, T2.PersonID, T2.PersonName, T3.PersonID, T3.PersonName
  2. FROM (tblPerson As T1 LEFT JOIN (tblPerson As T2
  3. LEFT JOIN tblPerson T3 ON T2.ChildID=T3.ParentID)
  4. ON T1.ChildID = T2.PersonID)
  5.  
I'm not sure what you are trying to represent in your treeview but this should give you some ideas.
May 2 '08 #2

FishVal
Expert 2.5K+
P: 2,653
....

tblPerson
PersonID (Primary key)
PersonName
ChildID (Foreign key referencing the primary key of its own table)

.....
Actually ChildID reference should be replaced with ParentID reference as long as tree node may have one parent and multiple childs.

tblNodes
keyNodeID (PK)
txtNodeName (Text)
keyParentNodeID (FK(tblNodes.keyNodeID))

If number of parents is expected to be more than one, then additional table to implement many-to-many relationship is needed.

tblNodes
keyNodeID (PK)
txtNodeName (Text)

tblNodeRelations
keyParentNodeID (FK(tblNodes.keyNodeID))
keyChildNodeID (FK(tblNodes.keyNodeID))

Regards,
Fish
May 3 '08 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Thanks fish, I was looking at it purely from the database point of view and not the treeview structure. Your suggestion makes more sense.
May 5 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.