My database uses a table of attributes to define fields that could potentially change or be added, depending on what contracts we have open for our fiscal years.
For starter, I'll describe the structure I would normally have done if this was a database specially for a contract.
A contract includes several services.
A services may have roles, usually one, but is one-many because I cannot guarantee that it always will be one-one.
One of role being defined for a current contract is "Case Management Client".
We are required to ask our clients what their needs are for communication and what reasonable accommodation we can provide to them. This is "Check where all apply", so it's a many-many relationship with a lookup table. All other personal data already have their respective table to go to.
Next, a client can have cases. Most of time, it'll be one per contract year, but there is possiblity that it could be closed mid-year, then re-opened the same year. Therefore, one-many client->cases. We also need to know when the case was opened and closed.
Now, every case has topic that needs to be resolved one way or other. We then need to set date topic has been identified, when it's been resolved and how it was resolved. So, one case -> many topics.
To summarize:
1 Case Management client -> Many Cases
1 Case -> Many Topics
Now, because I have no guarantee that contract terms will be same whenever we renew, and because we need to allow incorporating in new contracts, I need the database to be flexible so it's a simple matter of adding the required information then everything takes care of itself and I just need to worry about the reporting. This is where the table of Attributes comes in the picture.
tblAttributes
AttributesID (Primary Key)
DataTypeID (Lookup table specifying what kind of data type this will use)
ControlTypeID (Lookup table telling what control this uses)
FieldCaption
RequiredEntry
ValidateOnEntry
ValidateRule
ValidateText
AttrDefaultValue
LookUpTable (Identifies if an attribute uses a lookup table; all lookup tables are many-many by default)
This is basically a copy of what you would see on table design view. The attributes applies to both services and roles.
For example, we need to ask everyone what their communication needs and reasonable accommodations are; this would go under Role-Attribute, as this is something descriptive of the role as a client, and is asked once.
Then there's service-attributes; that's where we put the case and topics in.
But here's two problem: As I described, a case can have many topics and the tblAttributes "flatten" the one-many relationship. I'd need a mean to somehow represent the relationship between the attribute.
Secondly, I'd need to be able to "group" the attributes as well. For example, a case has a "Case Open date", and "Case Close date"; which are currently stored as two separate attributes when in the above design, would have been in one table.
My initial ideas are:
1) Add a field and name it "AttrTag", something akin to Tag property used in control objects; to tell me something about how attributes will be group so it can be grouped in a meaningful way.
2) While the #1 is a good solution for the second problem, it won't be as good for the first problem, as if I need to do a query of virtual one-many attributes, this is strictly one level deep; what if I need it to be two level deep? I'm SOL if this happens. I thought about self-join, but wasn't sure how this would help un-flatten the implicit relationships between attributes.
Any suggestions will be much, much appreciated!
For starter, I'll describe the structure I would normally have done if this was a database specially for a contract.
A contract includes several services.
A services may have roles, usually one, but is one-many because I cannot guarantee that it always will be one-one.
One of role being defined for a current contract is "Case Management Client".
We are required to ask our clients what their needs are for communication and what reasonable accommodation we can provide to them. This is "Check where all apply", so it's a many-many relationship with a lookup table. All other personal data already have their respective table to go to.
Next, a client can have cases. Most of time, it'll be one per contract year, but there is possiblity that it could be closed mid-year, then re-opened the same year. Therefore, one-many client->cases. We also need to know when the case was opened and closed.
Now, every case has topic that needs to be resolved one way or other. We then need to set date topic has been identified, when it's been resolved and how it was resolved. So, one case -> many topics.
To summarize:
1 Case Management client -> Many Cases
1 Case -> Many Topics
Now, because I have no guarantee that contract terms will be same whenever we renew, and because we need to allow incorporating in new contracts, I need the database to be flexible so it's a simple matter of adding the required information then everything takes care of itself and I just need to worry about the reporting. This is where the table of Attributes comes in the picture.
tblAttributes
AttributesID (Primary Key)
DataTypeID (Lookup table specifying what kind of data type this will use)
ControlTypeID (Lookup table telling what control this uses)
FieldCaption
RequiredEntry
ValidateOnEntry
ValidateRule
ValidateText
AttrDefaultValue
LookUpTable (Identifies if an attribute uses a lookup table; all lookup tables are many-many by default)
This is basically a copy of what you would see on table design view. The attributes applies to both services and roles.
For example, we need to ask everyone what their communication needs and reasonable accommodations are; this would go under Role-Attribute, as this is something descriptive of the role as a client, and is asked once.
Then there's service-attributes; that's where we put the case and topics in.
But here's two problem: As I described, a case can have many topics and the tblAttributes "flatten" the one-many relationship. I'd need a mean to somehow represent the relationship between the attribute.
Secondly, I'd need to be able to "group" the attributes as well. For example, a case has a "Case Open date", and "Case Close date"; which are currently stored as two separate attributes when in the above design, would have been in one table.
My initial ideas are:
1) Add a field and name it "AttrTag", something akin to Tag property used in control objects; to tell me something about how attributes will be group so it can be grouped in a meaningful way.
2) While the #1 is a good solution for the second problem, it won't be as good for the first problem, as if I need to do a query of virtual one-many attributes, this is strictly one level deep; what if I need it to be two level deep? I'm SOL if this happens. I thought about self-join, but wasn't sure how this would help un-flatten the implicit relationships between attributes.
Any suggestions will be much, much appreciated!