Ask a Question related to ASP Database, Design and Development.
-
Dragonhunter #1
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
-
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... -
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... -
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... -
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 ... -
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... -
Aaron Bertrand - MVP #2
Re: Need advice on getting data out of normalized database
> set rs2 = oConn.Execute("SELECT Rarity_Options FROM Rarity WHERE
Ugh, no, you should not be nesting recordsets. Use joins and make your life> ID="&rs.fields("Rarity").Value)
easier.
[url]http://www.aspfaq.com/2241[/url]
Aaron Bertrand - MVP Guest
-
Jeff Cochran #3
Re: Need advice on getting data out of normalized database
On Tue, 23 Sep 2003 18:10:06 GMT, Dragonhunter
<dragonhunter97@yahoo.com> wrote:
Normally (pun intended) when you normalize to separate tables, you use>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!!
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



Reply With Quote

