Long SQL Statement Via ASP

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Long SQL Statement Via ASP

    Not sure if this is a more Access related question or a
    more ASP related question, or both, or neither.

    I'm trying to convince another developer to redesign the
    schema of a database we use to generate an ASP page.
    Here's the Cliff's Notes version of our current setup -

    We provide visitors to our Web site a way to search this
    database. They are allowed to pick several search
    criteria, one of which they select from a long list of
    choices. The way that our database is currently set up,
    each record has a comma delimited list in the field for
    these choices. So if the select box on the form looks
    like this -

    Apples
    Oranges
    Pears
    Grapes
    ....

    - then one record in this table might have a field named
    Fruit that has the value "Apples, Pears, Grapes".

    There could be...geez...a dozen or more options for this
    value. To accomidate, we build a massive SQL statement
    that we pass to the DB. In addition to the SQL to handle
    the other search points, the section dealin with this
    field contains four or five LIKE operators, to try and
    find the value with a comma after it (as if it were at the
    beginning of the list), a comma on either side (as if it
    were buried in the middle of the list), no commas (as if
    it were the only option for this row), etc. etc. etc.

    I want to break out that field and make a union table
    Records <-> Fruit. However, doing so would entail
    modifications to other apps besides this Web site, and my
    buddy is leery of doing that unless we're going to
    recognize real solid gains from tightening up our design.

    So....based on what I've described, do you think that our
    app would be better (i.e., run faster, more efficient,
    etc.) if we made the change I propose? I estimate that
    we'd cut the length of the SQL statement almost in half if
    we did this.
    MDW Guest

  2. Similar Questions and Discussions

    1. Question about a long session timeout (somewhat long)
      I've been told by my developers to increase the asp.net session timeout to 72 hours. Being a server guy, it concerns me because of the obvious...
    2. Big statement locks table too long
      We have a few sql statements that take up to 10 minutes to run. they are run like INSERT INTO blah (SELECT... and that Select probably has a join...
    3. How long
      How long does it take to install 7.0 onto a server remotely? I am thinking of setting up my own box form some of my sites and I am comfortable with...
    4. thoughts about DBI [LONG]
      Hi gurus and nubys, After the recent thread about XML GUIs and common apis, I thought again about DB-API. I mean: why do we have DBI? I suppose...
    5. IDS 7.3* - Long long long checkpoint !
      I've noticed very long checkpoints in the online.log file. What does IDS do in a checkpoint that can take so long ? Environnement: IDS running on...
  3. #2

    Default Re: Long SQL Statement Via ASP

    > - then one record in this table might have a field named
    > Fruit that has the value "Apples, Pears, Grapes".
    I strongly recommend you use a many-to-many relationship, instead of trying
    to combine multiple attributes into one element.
    > the other search points, the section dealin with this
    > field contains four or five LIKE operators, to try and
    > find the value with a comma after it (as if it were at the
    > beginning of the list), a comma on either side (as if it
    > were buried in the middle of the list), no commas (as if
    > it were the only option for this row), etc. etc. etc.
    Well, if this is your biggest problem at the present time, you could work
    around this by thinking outside the box for a moment::

    WHERE ',' + column + ',' LIKE '%,apple,%'

    However, breaking your fruits out into a fruit table and linking them to the
    actual data seems to make more sense. Not only do you avoid parsing strings
    to run queries (read: no index!), you can save gobs of spacing by only
    actually naming a fruit once, and representing it by a smaller datatype
    (e.g. TINYINT = 1 byte) wherever it is needed. This way, too, if Florida
    decides to change the name 'orange' to 'gatorfruit' due to a substantial
    investment from a certain school, you only have to change the word in one
    place in your entire database. Consider:

    CREATE TABLE Fruits
    (
    FruitID TINYINT IDENTITY(1,1)
    PRIMARY KEY CLUSTERED,
    FruitName VARCHAR(20)
    )

    CREATE TABLE OtherData
    (
    SomePrimaryKeyID INT
    )

    CREATE TABLE FruitLookup
    (
    SomePrimaryKeyID INT,
    FruitID TINYINT
    )



    Aaron Bertrand - MVP Guest

  4. #3

    Default Re: Long SQL Statement Via ASP

    DO IT.
    Not only that, you are likely to run into problems in the future that aren't
    knowable now.


    <anonymous@discussions.microsoft.com> wrote in message
    news:02f301c3a4b1$83265540$a501280a@phx.gbl...
    >
    > >-----Original Message-----
    > >> - then one record in this table might have a field named
    > >> Fruit that has the value "Apples, Pears, Grapes".
    > >
    > >I strongly recommend you use a many-to-many relationship,
    > instead of trying
    > >to combine multiple attributes into one element.
    > >
    > >> the other search points, the section dealin with this
    > >> field contains four or five LIKE operators, to try and
    > >> find the value with a comma after it (as if it were at
    > the
    > >> beginning of the list), a comma on either side (as if it
    > >> were buried in the middle of the list), no commas (as if
    > >> it were the only option for this row), etc. etc. etc.
    > >
    > >Well, if this is your biggest problem at the present
    > time, you could work
    > >around this by thinking outside the box for a moment::
    > >
    > >WHERE ',' + column + ',' LIKE '%,apple,%'
    > >
    > >However, breaking your fruits out into a fruit table and
    > linking them to the
    > >actual data seems to make more sense. Not only do you
    > avoid parsing strings
    > >to run queries (read: no index!), you can save gobs of
    > spacing by only
    > >actually naming a fruit once, and representing it by a
    > smaller datatype
    > >(e.g. TINYINT = 1 byte) wherever it is needed. This way,
    > too, if Florida
    > >decides to change the name 'orange' to 'gatorfruit' due
    > to a substantial
    > >investment from a certain school, you only have to change
    > the word in one
    > >place in your entire database. Consider:
    > >
    > >CREATE TABLE Fruits
    > >(
    > > FruitID TINYINT IDENTITY(1,1)
    > > PRIMARY KEY CLUSTERED,
    > > FruitName VARCHAR(20)
    > >)
    > >
    > >CREATE TABLE OtherData
    > >(
    > > SomePrimaryKeyID INT
    > >)
    > >
    > >CREATE TABLE FruitLookup
    > >(
    > > SomePrimaryKeyID INT,
    > > FruitID TINYINT
    > >)
    > >
    > >
    > >
    > >.
    > >
    >
    > I second that motion. Always normalize, unless there is a
    > definite performance advantage not to.
    > Other selling points: "Maintainability"
    > Don't want to be crude, but if it had been built right the
    > first time, you wouldn't have this problem.

    Jeff Clark Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139