I have a question concerning table design. I have a solution that should work in my opinion but doesn't.
Consider having two Entities "Subject" and "Process", both with certain attributes. Every "Subject" may be associated with multiple "Processes". Depending on which "Process" is chosen there is a varying number of the entity "Process-Property". In other words when the User associates a "process" with a "subject" he should only be able to edit the "properties" specifically linked to it.
Ultimately I want the User to be able to do 3 things:
- Creating new "Processes" and specifying the "Properties" asscociated with it
- List all "Processes" of a certain "Subject" even if there are no "Properties" linked to it
- Associate a "Process" with a "Subject" and only allow the predefined "Properties" to be evaluated
So the table design should be something like:
- tblSubject={SubjectID,...}
- tblProcess={ProcessID,...}
- tblProcessProperty={PropertyID,...}
- tblRelationProcessProperty={RelationProcessPropertyID, ProcessID, PropertyID}
- tblRelationSubjectProcessProperty={RelationID, RelationProcessPropertyID, SubjectID, PropertyValue}
This does obviously work as long as there is a "Property" associated with every "Process". So my mistake is not to directly link "Subject" to "Process" but then I can't get the table design straight.
Any help is appreciated.
It looks to me like your trying to implement a sort of EAV (Entity-Attribue-Value) design.
Your table seems ok, but this design inherently requires complicated SQL.
There are different methods of doing this but based on your tales above I would go with something like this.
Your property would simply look like this:
Your RelationshipProcessProperty could look like this:
Your SQL is where it would get complicated. Doing a 'generic' design like this has it's impliations as you're looking for multiple values in the same table.
You can use this method to get multiple properties for the same process.
In order to have specified properties for a specified process, you would need to create Process Type Table:
And this does mean that you will need to add a foreign key to your process table to link it to which type it is. You can then link your ProcessType table to your Property table with a relationship table that defines all of the available types.
Then to find out all of the available properties to that process type, you would have a relatively simple query
I think that this is the sort of thing you're looking for (though i could be completely off). If this is what you're looking for, there's a really good post here that makes some good points.
Also, I'm almost 100% there are better ways to do my long ';with' query - but this is all I know. Hopefully someone else can provide a better one. The point is that with this design, you will need sub-queries one way or another.
If you already have an idea, what you want to store in the schema, a good strategy for creating the schema itself is:
In your case, in step 1 you should have something like
If you have different types of processes, you can think about specialization of the Process-entity. If you really want to chose the concrete process-properties for every process, you should probably make the has-relationship of cardinality m:n.
In the ER-diagram the validity check (your 3rd item) cannot be done even if you had another relationship. In an SQL schema you could use check constraints to enforce this, or let the application handle validity before inserting new processes.