Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In a database, we store a hierarchy of objects with:
- A table OBJECT_NODE containing a list of objects, each object is identified by a numeric value “ID”
- And a table OBJECT_TREE containing the parent ship between these objects

SQL
Create Table OBJECT_NODE ( 
	ID 	int, 
	NAME varchar(255) )	Create Table OBJECT_TREE ( 
	PARENT_ID 	int, 
	CHILD_ID 	int )

For example:

1 ________2________3_______6
| |
| |______7
|
|
|______4________8
| |
| |______9
|
|
|______5 OBJECT_NODE OBJECT_TREE
ID NAME PARENT_ID CHILD_ID
1   N1  1   2
2   N2  2   3
3   N3  2   4
4   N4  2   5
5   N5  3   6
6   N6  3   7
7   N7  4   8
8   N8  4   9
9   N9

For the following 2 questions, please write the procedure for an undefined number of levels in the hierarchy.

1/ Create a SQL Procedure giving all down hierarchy objects of a given node
(in the upper example, all down hierarchy objects of node 2 are 3, 4, 5, 6, 7, 8, 9)

SQL
Create Procedure GET_OBJECT_CHILDREN (I_PARENT_ID int)



2/ Modify the procedure to give only leaves (objects with no children)
(in the upper example, all leaves objects of node 2 are 5, 6, 7, 8, 9)


Please provide answers to above question based on above hierarchy ..............Plz help me out
Posted
Updated 14-Feb-13 10:43am
v3

1 solution

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
Comments
mahesh.b.p.c 14-Feb-13 10:50am    
ok ,if u have answer just help me out
OriginalGriff 14-Feb-13 10:51am    
Have you tried to do anything yourself?
joshrduncan2012 15-Feb-13 9:23am    
My 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900