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)
 Need feedback.What do you think about this design?

Author  Topic 

Staryon
Starting Member

10 Posts

Posted - 2006-01-05 : 14:41:11
Hi,

I need to store a hierarchy in my database (a tree)
I have 3 types of data: Cases, Groups and Users. I can have any combination of them.

Check the following link ('Groups', 'Cases', 'Users' and 'Tree' will be tables in my database):
http://www.lemforever.com/temp/tree.jpg

What do you guys think? Do you think is a good solution? I still want to have a relational database
and I don't want to violate any integrity rules.

I based my solution on the article found here
http://www.sqlteam.com/item.asp?ItemID=8866
In my case is a little bit more complex, because I have different entities, not only Employees.

Thanks a lot.

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2006-01-05 : 17:18:26
Have a constraint such that only one of FK_userID, FK_caseID or FK_groupID is not null.

check(
case when FK_groupID is null then 0 else 1 end+
case when FK_caseID is null then 0 else 1 end+
case when FK_userID is null then 0 else 1 end
=1)

rockmoose
Go to Top of Page

Staryon
Starting Member

10 Posts

Posted - 2006-01-09 : 15:21:00
Thanks a lot, rockmoose. I will add that constraint to my database.

Best regards

Go to Top of Page
   

- Advertisement -