I’m quite new to MySQL and do not really know how to create a good layout for the following setup:
A riddim (rythm) can hold several tunes (songs). A song has the following information/fields: name, artist, label, producer, last modified timestamp, year, lyrics, flag, tag, source.
A riddim has the fields name, last modified, genre, youtube and image.
Here is an illustration for better understanding:
http://img194.imageshack.us/img194/6553/93112345.png
If I put all the information in one table I will have redundant data (such as genre or image), as every row with an artist/tune would have the riddim (rythm) it was sung on in it.
Currently my tables look like the following:
RIDDIMS table:
+---------------+--------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+-------------------+-------+
| riddim | varchar(255) | NO | MUL | NULL | |
| genre | varchar(9) | NO | | NULL | |
| youtube | varchar(11) | NO | | NULL | |
| image | varchar(11) | NO | | NULL | |
| last_modified | timestamp | NO | | CURRENT_TIMESTAMP | |
+---------------+--------------+------+-----+-------------------+-------+
TUNES table:
+---------------+--------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+-------------------+-------+
| riddim | varchar(255) | NO | MUL | NULL | |
| artist | varchar(255) | NO | MUL | NULL | |
| tune | varchar(255) | NO | | NULL | |
| label | varchar(255) | NO | | NULL | |
| producer | varchar(255) | NO | | NULL | |
| year | varchar(4) | NO | | NULL | |
| lyrics | text | NO | | NULL | |
| flag | varchar(12) | NO | | NULL | |
| tag | varchar(255) | NO | | NULL | |
| source | varchar(255) | NO | | NULL | |
| last_modified | timestamp | YES | | CURRENT_TIMESTAMP | |
+---------------+--------------+------+-----+-------------------+-------+
But I’m sure it is not a good layout. Do you guys have suggestions on how the tables/database structure should look like?
Having the ‘riddems’ and ‘tunes’ in seperate tables is the right structure to use. Basically model your data as signular objects, if certain fields actually belong to two different objects, it should be in two different tables.
To connect the too tables together, on the table that belongs to the parent table (in this case a riddem has many tunes so tunes belongs to riddem) put a reference to the parents id field. So in this case the tunes table should have a field called ‘riddem_id’ which is set to the riddem the tune belongs to.