![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I have a to design a structure for a table with many attributes containing Yes of No values. The program I write, has to react in different ways corresponding the Yes/No-values in the different attributes. For many records most of those values will be "No", as the program will perform an action only for a few records. This is all to avoid hard-coded checks. The real situation is way too business related to explain, but as an example the following will do: table: Furniture attributes: ID Name HasLock At the beginning, only a cupboard will have the attribute HasLock to Yes, all the other records will have this attribute to No. The program which uses these records will treat it in a way like: ... IF Haslock=yes THEN CreateLock() In this way, it is very easy for the user to create a "Commode" and let the program create a lock for it, without having to change the program. But only very few records will have the HasLock attribute to Yes. Furthermore, as many tests in the program depend on attributes of the furniture (HasWheels, NeedToBePaint, ...), the table will have a lot of attributes having Yes/No values. And every change request to my program will probably end up with the creation of an additional column in the table. Now, I came up with an idea of setting up a table structure in two levels: the first level containing a unique id and the name, and a second table with only those attributes which are "Yes": Table: Furniture Attributes: ID Name Table: Furniture-attribute Attributes: Furniture-ID Attribute-Name This will generate records in the Furniture table like: ( 123, "Cupboard") ( 456, "Chair") and records in the Furniture-attribute table like: ( 123, "HasLock") ( 456, "HasWheels") To be more flexible, I would extend the Furniture-attribute table like: Table: Furniture-attribute Attributes: Furniture-ID Attribute-Name Attribute-Type Attribute-Value Validity-begin-date Validity-end-date ...so I can "switch on and off" attributes on any date in the future. What are the pro's and con's for such an approach? Anja. |
#3
| |||
| |||
|
|
Table: Furniture-attribute Attributes: Furniture-ID Attribute-Name Attribute-Type Attribute-Value Validity-begin-date Validity-end-date What are the pro's and con's for [above] approach? |
#4
| |||
| |||
|
|
Why not just have a "HasLock" relation with the id's of the furniture with locks? And a "HasWheels" relation with the id's of the furniture with wheels?- Tekst uit oorspronkelijk bericht niet weergeven - |
#5
| |||
| |||
|
|
Why not just have a "HasLock" relation with the id's of the furniture with locks? And a "HasWheels" relation with the id's of the furniture with wheels?- Tekst uit oorspronkelijk bericht niet weergeven - Your solution creates a lot of similar tables, whereas mine groups all those tables into one. Creation of new attributes on the fly is done adding a record in my solution and creating a new table in yours. So my opinion is that my solution is preferable. But I'm open to all remarks! Anja. |
#6
| |||
| |||
|
|
Why not just have a "HasLock" relation with the id's of the furniture with locks? And a "HasWheels" relation with the id's of the furniture with wheels?- Tekst uit oorspronkelijk bericht niet weergeven - Your solution creates a lot of similar tables, whereas mine groups all those tables into one. Creation of new attributes on the fly is done adding a record in my solution and creating a new table in yours. So my opinion is that my solution is preferable. But I'm open to all remarks! There are two schools of thought as to whether the addition of a new |
#7
| |||
| |||
|
|
There are two schools of thought as to whether the addition of a new attribute should or should not require additional data definition. Adding a row to a table is data manipulation. altering a table to add a new column is data definition. Creating a new table is likewise data definition. I'm of the school of thought that data in a database is managed better when the right to create and alter data definitions is severely restricted, while the right to manipulate data is extended to the applications that interact with the database. The other school of thought is that the superior flexibility of defining new attributes without altering any database definitions overrules the data management advantages in prohibiting the same. I can't defend this school of thought (apparently yours) because, in my view, it leads inexorably to undocumented and therefore unusable data. Hope this helps. |
#8
| |||
| |||
|
|
There are two schools of thought as to whether the addition of a new attribute should or should not require additional data definition. Adding a row to a table is data manipulation. altering a table to add a new column is data definition. Creating a new table is likewise data definition. I'm of the school of thought that data in a database is managed better when the right to create and alter data definitions is severely restricted, while the right to manipulate data is extended to the applications that interact with the database. The other school of thought is that the superior flexibility of defining new attributes without altering any database definitions overrules the data management advantages in prohibiting the same. I can't defend this school of thought (apparently yours) because, in my view, it leads inexorably to undocumented and therefore unusable data. Hope this helps. Good point, David. Although here I've found a lot of small attributes only containing Y/N- values, for which nobody knows what they're standing for. When creating new records, they are always filled with the default. It's a beautiful example that adding rows does not lead to more documented use. I do not belong to any school, I'm only open-minded. I think I look to data the wrong way. IfI see records with many attributes, mostly all 'N', except for the column HasWheels, I get confused. When I only see one record telling (123, HasWheels,Y), it points me directly to the fact that furniture 123 has something special: it has wheels! Is adding a column not forcing the application to stop as it will lock the entire table, or am I wrong? It depends on which DBMS you are using. The best case I have seen (some ten |
#9
| |||
| |||
|
|
snip ...There is nothing wrong with having a lot of similar tables. Having a separate relation for each type of atomic fact is a good thing, because it simplifies the representation of information. |
#10
| |||
| |||
|
|
On Tue, 04 Sep 2007 00:51:51 -0400, Brian Selzer wrote: So, having lots of tables is good from a data-purity point of view... but spare a thought for the poor programmer who has to code for each table. One general table is far from perfect, and we will lose of a great many specific constraints that could help reduce data integrity problems... BUT we think we can run with it. In this particular case. |
![]() |
| Thread Tools | |
| Display Modes | |
| |