|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
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. |
|
#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. |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Too many columns? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|