Question

I have a table with components, other woth work orders and other with RepairTask. The relation of task with components are 1:N, one task it's only of one component. And tasks have a 1:N relationship with work orders because a task only can be in one work order. The relationship between components and work orders is N:N because one work order can affect to many components.

I would like to know:

Work order in which a component is repaired The task that a component have received. The task that I have done in a work order.

For that I think that there are two option, a cycle relationship between the three tables or a ternary relationship between the three tables.

OPTION 1: cycle relationship

Components(IDComponent, ...)
WorkOrders(IDWorkOrder, IDComponent, ...)
Tasks(IDTask, IDComponent, IDWorkOrder, ...)
ComponetsHasWorkOrders(IDComponent, IDWorkOrder)

OPTION 2: ternary relationship

Components(IDComponent, ...)
WorkOrders(IDWorkOrder, ...)
Tasks(IDTask, ...)
CompoentsHasWorkOrdersAndTasks(IDComponent, IDWorkOrder, IDTask)

In this second option I set that the IDTask must be unique, because the task has only be in one work order and in one component. So in this way I ensure the 1:N relation between tasks and components and 1:N between workOrders and Tasks.

One problem that I see in this solution is that if I delete a workorder for example, I delete the record in CompoentsHasWorkOrdersAndTasks, so I lost the relation between components and task. I would change the relation and allow null in a field that is part of the primary key, so this is not a good idea, so I need a dummy work order for this cases.

But I don't know if it's better a ternary relationship or a cycle relationship.

There are any other solution?

Thanks.

Was it helpful?

Solution

Note: OrderTaskNo in Task table is an integer; for every OrderID there is OrderTaskNo {1,2,3, ...}

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top