Jump to content

Database design - which is the best data type?


Recommended Posts

Designing a database and although I've made and redesigned loads in the past I've come across a small problem.

 

I need to create a table (ie. "genres") listing a load of music types (ie. folk, rock, pop etc.) which will be referenced via an albums table. Now an album can be more than one genre (ie. folk rock) and I'm wondering what would be the best way to go about it?

 

I was thinking of using a sort of bit definition:

1 Folk

2 Rock

4 Pop

8 Indie

16 Dance

 

So "folk rock" would be 3 (1+2) but not sure how to go about it as I've never needed to use anything like this before.

that is one way to do it, but as referenced in the link below, bitwise operations use BIGINT which maxes out at 2^64. This means you can only have 64 genres.

http://dev.mysql.com/doc/refman/5.0/en/bit-functions.html

 

The normal way of doing this is to have a third table that links albums to genres. So it would be called (for instance) album_genre_link and would have two columns, album_id and genre_id

While reading up on the BIT data type I found a site listing reasons why not to use it.

http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql

 

I checked out the SET data type then found out that the fields have to be defined upon database creation - I need the contents to be fluid so SET is no good.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.