|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I am planning a website using asp and access.
I have a table called Structure with the following fields (sample data): - Id (1) - Name (Mary) - Href (mary.htm) - Links (3#11#26#48) By using an asp script I intend to get the links field according to each page, break it up into an array and display the links. Another possibility would be to have a separate table (links) with the following structure: StructureId / LinkId 1 / 3 1 / 11 1 / 26 ... / ... Which way is better and esp. WHY? That is, at first glance, I don't see the advantages of the second version - the first seems clearer... Thank you. |
|
#2
|
|||
|
|||
|
I tend to prefer the second method, because it keeps the logic in the database, meaning that you can more easily manage or extend your database in the future. With the first method, you are dependent on your programming environment to break up the Links column into its separate elements. If you keep this method, then it is difficult to keep complete querying control of your data as it grows.
Now, a possible middle ground is to store the data as an "array" datatype, if your DBMS supports that type, but even then, you still should question the logic of that approach, especially as it relates to normalization of your whole database.
__________________
The real n-tier system: FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL Amazon wishlist -- rycamor (at) gmail.com |
|
#3
|
||||
|
||||
|
rycamor is right. The second approach is better and a more commonly accepted procedure. It's proper related normalization. The benefits are countless. Here's one:
You can now create a sql select statement to join both tables and cycle through the links, instead of having to rely on buggy programming to break apart the links string array: SELECT Name, LinkID FROM People, Links WHERE People.ID=Links.ID -Dave |
|
#4
|
||||
|
||||
|
coincidentally, i just answered this same question the other day
How to do looping in SQL http://searchdatabase.techtarget.co...x285649,00.html (free registration may be required) if you're an sql geek like me you might enjoy the snippet of sql that joe celko wrote in that article, that pulls out all the terms of a comma-separated list warning: not for the faint of heart rudy http://r937.com/ |
|
#5
|
|||
|
|||
|
Thank you all for your replies. It is clear to me now, that, although I had made a perfectly workable solution using the first option, the second one has quite a few advantages.
I was trying to implement something in the way WineIsGood suggested (great nick by the way .I also read the answer from r937 and his answer on Ask the Experts, but frankly it wasn't really clear to me... I'm not quite there yet But anyway, I got stuck implementing the solution: What did I do? Here's the SQL: SELECT Structure.Name, Structure.Href, Links.LinkId FROM Structure, Links WHERE Structure.Id = Links.Id AND Links.Id LIKE '" & strPageId & "'" strPageId is a variable containing a Structure.Id of the page, set elsewhere. Where did I go wrong? Thanks so much. |
|
#6
|
|||
|
|||
|
Oh right, completely forgot - my db looks like this:
table Structure - Id - Name - Href table Links - Id - LinkId Thanks |
|
#7
|
|||
|
|||
|
Yes! It works! Thanks for all your help!
|
|
#8
|
||||
|
||||
|
I'm glad it worked for you. If I could just make one suggestion, watch out with the LIKE clause. If you're trying to hit one unique record, use = instead of LIKE. If you're going to use LIKE, then use it for it's wildcard benefits like _ and % :
... WHERE LastName LIKE 'wine%' |
|
#9
|
|||
|
|||
|
WineIsGood, thank you, a good suggestion indeed! I'll be aware of that.
B.T.W: Great looking picture under your nick! Daughter? |
|
#10
|
||||
|
||||
|
Thanks
... yup, she'll be 2 this November.-Dave |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > a table with links - bad db design? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|