SunQuest
           Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old August 11th, 2003, 03:29 AM
matej matej is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Ljubljana, Slovenia
Posts: 9 matej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 sec
Reputation Power: 0
Question a table with links - bad db design?

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.

Reply With Quote
  #2  
Old August 12th, 2003, 09:53 AM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Pembroke Pines, Florida, USA
Posts: 2,300 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 3 h 2 m 4 sec
Reputation Power: 43
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

Reply With Quote
  #3  
Old August 12th, 2003, 03:42 PM
WineIsGood's Avatar
WineIsGood WineIsGood is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: New York
Posts: 49 WineIsGood User rank is Private First Class (20 - 50 Reputation Level)WineIsGood User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 m 51 sec
Reputation Power: 6
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

Reply With Quote
  #4  
Old August 12th, 2003, 09:30 PM
r937's Avatar
r937 r937 is online now
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,310 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 4 h 19 m 45 sec
Reputation Power: 888
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/

Reply With Quote
  #5  
Old August 13th, 2003, 02:14 AM
matej matej is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Ljubljana, Slovenia
Posts: 9 matej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old August 13th, 2003, 02:23 AM
matej matej is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Ljubljana, Slovenia
Posts: 9 matej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 sec
Reputation Power: 0
Oh right, completely forgot - my db looks like this:

table Structure
- Id
- Name
- Href

table Links
- Id
- LinkId

Thanks

Reply With Quote
  #7  
Old August 13th, 2003, 02:39 AM
matej matej is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Ljubljana, Slovenia
Posts: 9 matej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 sec
Reputation Power: 0
Yes! It works! Thanks for all your help!

Reply With Quote
  #8  
Old August 13th, 2003, 08:49 AM
WineIsGood's Avatar
WineIsGood WineIsGood is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: New York
Posts: 49 WineIsGood User rank is Private First Class (20 - 50 Reputation Level)WineIsGood User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 m 51 sec
Reputation Power: 6
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%'

Reply With Quote
  #9  
Old August 14th, 2003, 04:49 AM
matej matej is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Ljubljana, Slovenia
Posts: 9 matej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 sec
Reputation Power: 0
WineIsGood, thank you, a good suggestion indeed! I'll be aware of that.
B.T.W: Great looking picture under your nick! Daughter?

Reply With Quote
  #10  
Old August 14th, 2003, 06:37 AM
WineIsGood's Avatar
WineIsGood WineIsGood is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: New York
Posts: 49 WineIsGood User rank is Private First Class (20 - 50 Reputation Level)WineIsGood User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 m 51 sec
Reputation Power: 6
Thanks ... yup, she'll be 2 this November.
-Dave

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > a table with links - bad db design?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway