SunQuest
           Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

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 Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old November 3rd, 2003, 09:39 AM
dvorskytomas dvorskytomas is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Krnov, Czech Republic
Posts: 8 dvorskytomas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Too many columns?

Hi,
my problem is that in a db may thousands of companies and each of them can offer services in many categories. I've created over 1200 different categories and am thinking about creating just two tables:
[code]
create table activities (
activity_id int(4) not null primary key,
activity_name varchar(75) not null,
unique key (activity_name)
);

and
create table object_activity (
objekt_id int(10) not null primary key,
act1 tinyint(1),
act2 tinyint(1),
...
act1200 tinyint(1)...

this would enable me to do searches like SELECT * from object_activity where act1=1 to pull all companies which do offer services in this particular area.

But I'm just not quite sure if this kind of design - 1200 columns - isn't too much.

Other solution is that the activites can be divided into about 10 groups, these devided into lets say 150 subgroups and into these can be added the particular activities. Should I create rather more tables and make the queries a little more complicated or is the first design fine?

Hope I did describe it correctly and that someone could give me an answer.

Reply With Quote
  #2  
Old November 3rd, 2003, 05:23 PM
-vertigo- -vertigo- is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Louth, Lincolnshire
Posts: 314 -vertigo- User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 24 sec
Reputation Power: 2
RE: Too many columns?

The relationship you have described between objects and activities is many-many. Therefore you need an associative table to store which objects participate in which activities.

You have got this, the table object_activity, but here you must have one row per object AND activity. For each object-activity connection a row will exist in this table. The only columns will be object_id, activity_id, and anything you want to store about that relation, like perhaps the date it was established, etc.

When you have a dimension table like activity with one item per row, never use columns for this in another table, but stick to rows throughout.

Think of it this way. To add a new activity to the activity table, a new row gets added. So it is wrong to require a new column to be added in object_activity for the new activity.

Reply With Quote
  #3  
Old November 4th, 2003, 10:28 AM
dvorskytomas dvorskytomas is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Krnov, Czech Republic
Posts: 8 dvorskytomas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Too many columns?

OK, I hope I understand...
So in the new table design of object_activities there would be just multiple entries for every object? Like:
(object_id) | (activity_id)
1 | 256
1 | 378
and so on...

Think I got it now, thank you vertigo

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Too many columns?


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 1 hosted by Hostway