[quoted text, click to view] Evertjan. wrote:
> ?? wrote on 27 mrt 2004 in
>> I'm working on revamping an application I originally helped
>> architect. At the time I first created it, it was my first DB/ASP
>> project and a lot of things in it now seem glaringly wrong about it.
>> Namely, there is one field in the table we use that breaks the
>> cardinal rule of atmocity - it contains several values (maybe as
>> many as a dozen) seperated by commas. We have a userform where the
>> user selects a dropdown and then we try to return all rows where
>> their selected value appears in this list.
>>
>> I have been trying to convince the person overseeing this (my boss, I
>> guess you could say) that we need to create a M:M table and
>> essetially start over. However, he's fixated on the idea that if we
>> create a temp. recordset, it's going to contain more rows than the
>> current table and thus it will be "slower". But aside from being
>> extremely bad database design, I know that parsing out strings is
>> not exactly effiicient.
>
> using serverside split(",") is not that bad.
Unless you need to do it to every row in the table in order to search for a
value contained in this field. :-)
[quoted text, click to view] >
>> Does anyone have any links to sites that explain this better than I
>> am able to?
Using a single value in a field will allow you to index that field, making
searches much more efficient than the table scan required by storing
multiple values in that field. let me illustrate it like this:
Your current table probably contains data like this (using Evertjan's
example):
ID Properties OtherFields
1 1,big,blue ------
2 5,red,medium -----
3 28,red, small -----
etc.
To find the records containing the word "red", the query engine needs to
look at every record in this table. This operation is known as a table scan.
It's an operation which should be avoided. With many rows, I think you can
see that this can be a resource- and time-consuming operation.
For an analogy, think about how hard it would be to find a name in a phone
book if the names were not arranged in alphabetical order.
Now let's look at the case where we break the properties out into a new
table as suggested by Evertjan. We now have a main table:
ID OtherFields
1 ----
2 ----
3 ----
And a properties table (I suspect "Property" might be a reserved keyword, so
you should come up with another name):
ID Property
1 1
1 big
1 blue
2 5
2 red
2 medium
3 28
3 red
3 small
Now we can put an index on the Property column and it will be a snap for the
query engine to find the two records where Property="red". When we use a
join in the query returning these records, you can assure your boss that the
query will not be returning extra records. This sql:
select m.ID, otherfields
from maintable m inner join propertytable p
on m.id = p.id and p.[Property] = "red"
will only return 2 records (try it). And it will do it extremely
efficiently.
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"