If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Projects, tasks, persons...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-09-07, 09:18
kaervas59 kaervas59 is offline
Registered User
 
Join Date: Jun 2007
Posts: 5
Projects, tasks, persons...

Hey my first post (yay!)

Here is my problem. I'm currently working on a database for a person project and I don't figure how to construct my relational model for that :

- A task can be a person task or a project task.
- A task can be a project task affected to a person registered to a project.
- If possible, I don't want to created separated table for the same data (task).

If somone has idea...
Attached Thumbnails
Projects, tasks, persons...-tasks.png  
Reply With Quote
  #2 (permalink)  
Old 07-09-07, 10:42
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
We don't really have enough information to go on:
* Is a task always either for a person or for a project (never both)?
* Can a task be associated with more than one person, or more than one project?
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 07-09-07, 11:10
kaervas59 kaervas59 is offline
Registered User
 
Join Date: Jun 2007
Posts: 5
Sorry for the missing information

* Is a task always either for a person or for a project (never both)?

Yup, never both.

* Can a task be associated with more than one person, or more than one project?

A task can be associated with more than one person or more than one project.

Thanks for the help.
Reply With Quote
  #4 (permalink)  
Old 07-09-07, 11:43
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
OK, then to preserve a single Tasks table you could do this:

* Add a column to Tasks called TaskType, constrained to be 'PERSON' or 'PROJECT'.
* Create a UNIQUE constraint on Tasks(TaskType,Id)
* Create a table PersonTasks like this:

create table PersonTasks
( PersonId REFERENCES Person
, TaskType varchar(6) CHECK (TaskType = 'PERSON')
, TaskId integer
, FOREIGN KEY (TaskType,TaskId) REFERENCES Tasks(TaskType,Id)
);

* Create a similar table ProjectTasks

Now when you create an association between a Person and a Task, you will only be allowed to choose 'PERSON' Tasks:

i.e. this will work:
Code:
insert into PersonTasks(personId,TaskType,TaskId) values (1,'PERSON',101);
but this will not (prevented by the CHECK constraint):
Code:
insert into PersonTasks(personId,TaskType,TaskId) values (1,'PROJECT',202);
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #5 (permalink)  
Old 07-09-07, 12:02
kaervas59 kaervas59 is offline
Registered User
 
Join Date: Jun 2007
Posts: 5
Thanks you a lot!
Reply With Quote
  #6 (permalink)  
Old 09-05-07, 00:44
PolarBear2k PolarBear2k is offline
Registered User
 
Join Date: Jun 2005
Posts: 79
Hi,

I think I have the same problem but mysql 5.0 doesn't support the CHECK constraint.
I have an "InvoiceLine" that contains a "Product" that can either be of type "A" or "B".
Tables "A" and "B" have a totally different structure.
I guess I also need to create two linking tables, "Product_A" and "Product_B" and create a field ProductType in the "Product" table.

Would the table structure for the two linking tables be the same as with the solution above? Can this work without the CHECK constraint?

Thanks
Reply With Quote
  #7 (permalink)  
Old 09-05-07, 06:53
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
if A and B are totally different, then InvoiceLine should contain two FKs, both of which should be NULLable, and only one of which will actually contain a value on any given row
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On