Need advice on getting data out of normalized database

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

  1. #1

    Default Need advice on getting data out of normalized database

    Hello all,

    Thanks to the advice of Manohar Kamath, Bob Barrows, Curt, Chris and
    others, I restructured my database for "normalization" where I have a
    main table with a couple columns and then in the columns I've got ID
    numbers of items in other tables. The idea makes sense. However, when
    I go to get data out of my database, it seems tedious. I'm wondering if
    I am doing it right. Is this how you guys would do it? I have a loop
    with a bunch of .execute statements in each (see code below) Any tips
    on how to improve it would be greatly appreciated!!

    -Dragonhunter

    Here's the table structures:

    ---Magic_Items_Table---
    ....other fields....
    Rarity (ID of item from Rarity table)
    Aura_Strength (ID of item from Aura_Strength table)
    Aura_Type (ID of item from Aura_Type table)

    ---Rarity Table---
    ID
    Rarity_Options

    ---Aura_Strength Table---
    ID
    Aura_Strength

    ---Aura_Type-----
    ID
    Aura_Type


    Dim oConn, sConnString
    Set oConn = Server.CreateObject("ADODB.Connection")
    sConnString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    "DBQ=" & Server.MapPath(database_relative_path) & ";"
    oConn.Open(sConnString)
    set rs = oConn.Execute("SELECT * FROM Magic_Items_Table")
    %>
    <table border="0" width="252" cellspacing="0" cellpadding="0">
    <%while not rs.EOF%>
    <%if (not isNull(rs.Fields("Description").Value)) then%>
    <tr>
    <td height="429" valign="top" >
    <table border="0" width="100%" cellspacing="0" cellpadding="0">
    <tr>
    <br/><strong>Rarity</strong>: <%
    if (not (isNull(rs.fields("Rarity").Value) or
    rs.fields("Rarity").Value = "")) then
    'Response.Write(">"&rs.fields("Rarity").Value&"<")
    set rs2 = oConn.Execute("SELECT Rarity_Options FROM Rarity WHERE
    ID="&rs.fields("Rarity").Value)
    If rs2.eof then
    Response.Write("EOF")
    Else
    Response.Write(rs2.Fields(0).Value)
    End if
    end if
    %>

    <br/><strong>Aura</strong>: <%
    if (not (isNull(rs.fields("Aura_Strength").Value) or
    rs.fields("Aura_Strength").Value = "")) then
    'Response.Write(">"&rs.fields("Rarity").Value&"<")
    set rs3 = oConn.Execute("SELECT Aura_Strength FROM Aura_Strength
    WHERE ID="&rs.fields("Aura_Strength").Value)
    If rs3.eof then
    Response.Write("EOF")
    Else
    Response.Write(rs3.Fields(0).Value)
    End if
    end if
    Response.Write(" ")
    if (not (isNull(rs.fields("Aura_Type").Value) or
    rs.fields("Aura_Type").Value = "")) then
    'Response.Write(">"&rs.fields("Rarity").Value&"<")
    set rs3 = oConn.Execute("SELECT Aura_Type FROM Aura_Type WHERE
    ID="&rs.fields("Aura_Type").Value)
    If rs3.eof then
    Response.Write("EOF")
    Else
    Response.Write(lcase(rs3.Fields(0).Value))
    End if
    end if

    %>

    </td>
    </tr>
    </table>
    </td>
    </tr>
    <%end if%>
    <%
    rs.movenext
    wend
    %>
    </table>

    Dragonhunter Guest

  2. Similar Questions and Discussions

    1. Need advice on extracting database entries
      I'm not sure how I need to proceed on this and can use a bit of advice. I have a non-profit's web site that wishes to allow their members to fill...
    2. Acsess database design advice?
      Hi. Working on a e-commerce site, using ASP/Acsess/Vbscript. This is prehaps a database organize question. I use an unique ID for each order...
    3. need an advice on running Database
      Hi, I have a small data base ~ 10 tables. each table get insert/update/delete few times a day. postgresql is running for a month. The load will...
    4. Need advice on structuring a database
      Hello, I want to build a database with two tables, Characters and Abilities. So in the first table I would have: # Character ...
    5. Second Normalized Form..
      If I am right...a table is in second normalized form if all the non-key attributes depend upon ALL the attributes contributing to Primary Key and...
  3. #2

    Default Re: Need advice on getting data out of normalized database

    > set rs2 = oConn.Execute("SELECT Rarity_Options FROM Rarity WHERE
    > ID="&rs.fields("Rarity").Value)
    Ugh, no, you should not be nesting recordsets. Use joins and make your life
    easier.
    [url]http://www.aspfaq.com/2241[/url]


    Aaron Bertrand - MVP Guest

  4. #3

    Default Re: Need advice on getting data out of normalized database

    On Tue, 23 Sep 2003 18:10:06 GMT, Dragonhunter
    <dragonhunter97@yahoo.com> wrote:
    >Thanks to the advice of Manohar Kamath, Bob Barrows, Curt, Chris and
    >others, I restructured my database for "normalization" where I have a
    >main table with a couple columns and then in the columns I've got ID
    >numbers of items in other tables. The idea makes sense. However, when
    >I go to get data out of my database, it seems tedious. I'm wondering if
    >I am doing it right. Is this how you guys would do it? I have a loop
    >with a bunch of .execute statements in each (see code below) Any tips
    >on how to improve it would be greatly appreciated!!
    Normally (pun intended) when you normalize to separate tables, you use
    JOIN statements to query the data you need. You may want to run
    through the tutorials at sqlcourse.com for a primer/review of SQL
    statements.

    Your code nests recordsets, which is messy and problematic, and you
    can handle the query in a simple JOIN on the relevant tables and
    columns in a single recordset and a single trip to the database.

    Jeff
    Jeff Cochran 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