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)
 Children with more than one parent

Author  Topic 

gbala
Starting Member

2 Posts

Posted - 2004-10-26 : 13:31:49
Hi All,
I am trying to design the database for a bug tracker application.
This is the information I am trying to model.

There are n number of products in the project. Each product has one or more modules. There are some modules that are common to more than one product. (i.e) Each module(child) can have more than one parent(Product).

Every bug reported can have more than one product impacted(Therefore modules as well).

These are some of the questions that I would need to answer.
1. bugs details product wise.(Only For product A, Only for Product B and bugs that Impacted both Product A and Product B)
2. Modules that are common to products.

Also I need to ensure that No module can be created with out a parent associated with it.
How I can complent this with a E-R diagram or What could be best tables to implement this relationship.(Product - Module - BUGS)

Thanks and Regards
Balachandar

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-10-26 : 13:41:12
Read through this:

http://www.seventhnight.com/treestructs.asp

this demonstrates building and working with multi-parent trees

Corey
Go to Top of Page

kselvia
Aged Yak Warrior

526 Posts

Posted - 2004-10-26 : 20:16:32
Corey, several questions about trees in SQL Usenet news groups latley.

http://www.developersdex.com/sql/message.asp?p=2290&ID=%3Ccf6ef14%2E0410242204%2E6fc9b99c%40posting%2Egoogle%2Ecom%3E

Would your model work for that type of question? I'd post your link as a suggestion I couldn't elaborate on it so...

--Ken
I want to die in my sleep like my grandfather, not screaming in terror like his passengers.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-10-26 : 22:30:50
I've never tried it out...
I'll take a look at it. I would assume that if it didn't work right out of the box that it could be done pretty easily.

I'll keep you posted.

Corey
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-10-27 : 08:53:54
Ken - I didn't really understand the sample data in the question. Can you either explain how it is supposed to be read or supply a sample set that I can understand how the data relates. I have an idea on adapting my process, but I'm not sure I'm thinking about the right kind of data...

Corey
Go to Top of Page

kselvia
Aged Yak Warrior

526 Posts

Posted - 2004-10-27 : 11:34:37
Here http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21180918.html , http://www.experts-exchange.com/Databases/Q_21180850.html, http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21180993.html is where he started the question I think. I sent him to the newsgroups.

--Ken
I want to die in my sleep like my grandfather, not screaming in terror like his passengers.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-10-27 : 14:18:51
Oh yeah... now that I see the orignal chart form, the question makes sense. I still am not sure where the numbers are coming in. I think my solution will adapt well... back in a bit!

Corey
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-10-27 : 15:20:02
Ken here is the solution using my tree example... the stuff in green is set up, blue is standard process, bold addresses his question.



/************************************************
_______Nancy_______
/ |
Andrew Janet
/ \ / |
Margaret Steven Michael Robert
/ \ / \ / |
Laura Ann Ina David Ron Dan
*************************************************/
Declare @nodes table (NodeId int, Name varchar(20), side int)
Insert Into @nodes Values(1,'nancy',0)
Insert Into @nodes Values(2,'andrew',0)
Insert Into @nodes Values(3,'janet',1)
Insert Into @nodes Values(4,'margaret',0)
Insert Into @nodes Values(5,'steven',1)
Insert Into @nodes Values(6,'michael',0)
Insert Into @nodes Values(7,'robert',1)
Insert Into @nodes Values(8,'laura',0)
Insert Into @nodes Values(9,'ann',1)
Insert Into @nodes Values(10,'ina',0)
Insert Into @nodes Values(11,'david',1)
Insert Into @nodes Values(12,'ron',0)
Insert Into @nodes Values(13,'dan',1)

Declare @tree table (pNodeId int, cNodeId int, processed bit default(0))
Insert Into @tree (pNodeId, cNodeId) Values (0,1)
Insert Into @tree (pNodeId, cNodeId) Values (1,2)
Insert Into @tree (pNodeId, cNodeId) Values (1,3)
Insert Into @tree (pNodeId, cNodeId) Values (2,4)
Insert Into @tree (pNodeId, cNodeId) Values (2,5)
Insert Into @tree (pNodeId, cNodeId) Values (3,6)
Insert Into @tree (pNodeId, cNodeId) Values (3,7)
Insert Into @tree (pNodeId, cNodeId) Values (4,8)
Insert Into @tree (pNodeId, cNodeId) Values (4,9)
Insert Into @tree (pNodeId, cNodeId) Values (5,10)
Insert Into @tree (pNodeId, cNodeId) Values (5,11)
Insert Into @tree (pNodeId, cNodeId) Values (6,12)
Insert Into @tree (pNodeId, cNodeId) Values (6,13)

--Select * From @Tree



Declare @pad nvarchar(100),
@lastCnt int
Set @Pad = '0000'

Declare @paths table (path nvarchar(1000), pNodeId int, cNodeId int)

Insert Into @paths
Select
path=right(@pad + convert(nvarchar,pNodeId),len(@pad))+';' + right(@pad + convert(nvarchar,cNodeId),len(@pad))+';',
pNodeId,
cNodeId
From @Tree where pNodeId=0

Update A
Set Processed = 1
From @Tree as A
Inner Join @paths as B
On A.pNodeId = B.pNodeId
and A.cNodeId = B.cNodeId

While exists(Select * From @tree Where Processed = 0)
Begin
Insert Into @paths
Select
path=path + case when B.cNodeId is not null then right(@pad + convert(nvarchar,B.cNodeId),len(@pad))+';' else '' end,
B.pNodeId,
B.cNodeId
From @Paths as A
Left Join @Tree as B
On A.cNodeId = B.pNodeId
Where B.Processed = 0

Update A
Set Processed = 1
From @Tree as A
Inner Join @paths as B
On A.pNodeId = B.pNodeId
and A.cNodeId = B.cNodeId
Where A.Processed = 0
End

--All paths to each nodeId
--Select path, cNodeId From @paths Where cNodeId is not null




Declare @nodeName varchar(20),
@side varchar(10),
@nodePath varchar(1000)

Set @nodeName = 'andrew'
Set @side = 'right'

Set @nodePath = (Select path From @paths Where cNodeId = (Select nodeId From @nodes where Name = @nodeName))

Select top 1 name
From
(
Select
path,
cNodeId,
side = case when @side='left' then abs(side-1) else side end
From @paths A
Inner Join @nodes B
On right(A.path,len(A.path)-len(@nodePath)) like ('%'+right(@pad+convert(nvarchar,B.nodeId),len(@pad))+';%')
Where path like (@nodePath + '%')
) Z
Inner Join @nodes Y
On Z.cNodeId = Y.nodeId
Group By path, cNodeId, name
Having count(*)=sum(Z.side)
Order by sum(Z.side) desc




Corey
Go to Top of Page

kselvia
Aged Yak Warrior

526 Posts

Posted - 2004-10-29 : 16:37:23
I posted a link to your suggestion in the newgroup but no one responded. :(

--Ken
I want to die in my sleep like my grandfather, not screaming in terror like his passengers.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-10-29 : 16:55:19
hehehe oh well... it was interesting anyway

Corey
Go to Top of Page
   

- Advertisement -