Jump to content


Photo

Organizing Sql Database


  • Please log in to reply
3 replies to this topic

#1 dyanc

dyanc

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 29 June 2011 - 03:37 PM

This question is probably outside the realm of this forum but I was hoping that someone might take pity on me! We have a large database of media outlets with names, contact info, etc. In a "category" column, we enter the focus of each contact - News, Politics, Health, Family, etc. (info is entered using shorter forms, i.e. N, POL, FAM, HL). We have some cases where one person will fall into more than one category, and I've been told that I can enter more than one category with a comma between (i.e., N, POL, HL). Question: Is there a limit to the number of categories that could be separated by a comma?

It has been suggested that we set up a separate column for each category (about 20), and then place a "Y" in each column that is appropriate for the contact. I think it would be unwieldy to have to look at 20 columns of categories before I even get to see my other information. Does anyone have a suggestion as to how others may have set up a similar database?

My knowledge of SQL and databases is VERY basic - I know enough code to write the SELECT statements that I need! Thanks.

#2 Larry Woods

Larry Woods

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • Gender:Male

Posted 29 June 2011 - 03:55 PM

This question is probably outside the realm of this forum but I was hoping that someone might take pity on me! We have a large database of media outlets with names, contact info, etc. In a "category" column, we enter the focus of each contact - News, Politics, Health, Family, etc. (info is entered using shorter forms, i.e. N, POL, FAM, HL). We have some cases where one person will fall into more than one category, and I've been told that I can enter more than one category with a comma between (i.e., N, POL, HL). Question: Is there a limit to the number of categories that could be separated by a comma?

It has been suggested that we set up a separate column for each category (about 20), and then place a "Y" in each column that is appropriate for the contact. I think it would be unwieldy to have to look at 20 columns of categories before I even get to see my other information. Does anyone have a suggestion as to how others may have set up a similar database?

My knowledge of SQL and databases is VERY basic - I know enough code to write the SELECT statements that I need! Thanks.

Dyanc:

First, if you are creating a column with a single category in it then you need to put a single category in it. Remember that as far as mySQL is concerned this is nothing but some text. If you choose to put multiple categories in a single field using commas to delete then you have created a string of characters. The point is that mySQL will NOT recognize this as being "multiple categories" but only as a string of text.

You could create multiple fields for categories but the "proper" way to do this is to create an additional table, say called "ownercategorylinks" that would have records that might look like "ownerID,category". And, better yet, you should have a table of "categories" with a schema like "categoryID,category" and then the "ownercategorylinks" schema would look something like "ownerID,categoryID". This way you can have unlimited owner/category combinations.

Hope this helps...

Larry Woods

#3 smine

smine

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts
  • Location:San Francisco, California, US

Posted 29 June 2011 - 04:27 PM

... In a "category" column, we enter the focus of each contact - News, Politics, Health, Family, etc. (info is entered using shorter forms, i.e. N, POL, FAM, HL). We have some cases where one person will fall into more than one category, and I've been told that I can enter more than one category with a comma between (i.e., N, POL, HL). ...

if the categories are well-defined and don't change often, you could use the SET datatype for the column. you can search for categories using something like "WHERE find_in_set('POL',category)". yes, you can have multiple values in the column, all the way up to every category.

i'm not saying this is ideal--some people hate using sets--but i think it would work and might be sufficient for your purposes. MySQL doc for SET datatype can be found here.

#4 peterlaursen

peterlaursen

    Advanced Member

  • Admin
  • PipPipPip
  • 7,869 posts
  • Gender:Male
  • Location:Skagen, Denmark
  • Interests:well ... jazz/folk music, photography, chess, nature, ecology, history, bicycling, Highland Malts ... well, Lowland Malts and Cognac too actually :-) just wonder how I get the time to touch a computer! SQLyog and MONyog? no that's not interest, that's BASIC NEEDS simply!

Posted 30 June 2011 - 06:23 AM

You can check this: http://kb.askmonty.o...dynamic-columns

'dynamic columns' will be available in next MariaDB release. But with SQLyog GRID you will just have a single column (a BLOB I think) and CREATE/ALTER TABLE will need to be done by writing SQL, .





Computers make your grey hair come off ....

Peter Laursen
Webyog




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users