views:

502

answers:

8

I'm new to PHP and MySQL. For my project I want to make a site for lyrics. How to design the database and the relationships?

Here is what I have so far:

Artist

  • Artist_id
  • Artist_name
  • Artist_bio
  • Artist_thumb

Albums

  • Album_id
  • Artist_id
  • Genre_id
  • Album_title
  • Release_year

Genre

  • genre_id
  • genre_name

Tracks

  • track_id
  • track_title
  • album_id

Please let me know if I'm wrong

Thanks

A: 

How about having a separate table for album and a common table which defines the relationship between all the other tables?

Sri Kumar
Errr... A single relationships table? May I ask why?
Dominic Rodger
More foreign Key references could lead to problems... I thought this could simplify the database scheme.
Sri Kumar
Less relationships tables make foreign key constraints impossible, which I would have thought leads to more problems. How would a single relationship table be set up? `relationships` with `column1` and `column2`? How readable would joins be? I'd much rather have a table for each type of relationship, than have less tables. It'll make the database schema have more parts, but it'll make it a good deal less complex.
Dominic Rodger
+11  A: 
  1. Be consistent with whether your table names are singular or plural. My preference is singular, because then when you're doing multi-table queries, you can refer to a column simply as "track.id", rather than "tracks.id".

  2. Ensure all your table and field names are spelled correctly (i.e. "genre"); this is something that's a pain to change later.

  3. Finally, I wouldn't advise prefixing the column names with their parent table's name. It's just redundant.


artist

  • id
  • name
  • bio
  • thumb

album

  • id
  • artist_id
  • genre_id
  • title
  • release_year

genre

  • id
  • name

track

  • id
  • title
  • album_id
brianreavis
I was in the middle of writing a similar response; this man is correct.
Dean
And last but not least: Have a place to put the actual lyrics!
musicfreak
+1 The singular/plural table naming thing is difficult - yes you get to do `track.id`, but you also do `select * from track`, which reads less naturally than `select * from tracks` in my view.
Dominic Rodger
ya rite i will take care of singular/plural
sunidhi
+4  A: 

Your design looks pretty good. Some additional tables that you may want to add:

  • Playlist
  • PlaylistTrack
  • PlayedTrack

You could add additional fields to the Track table. For example:

  • trackSortOrder
  • trackYear
  • trackGenre
  • trackLength
  • userRating
  • bitRate
  • author
  • copyright
  • numberOfPlays
  • lastPlayedDate
  • dateAdded
Brian
What does `trackSortOrder` do in the `track` table?
Dominic Rodger
trackSortOrder would be used to specify the order of the tracks in a single album.
Brian
wht is the use of author as we already adding artist ?Trackyear is already we added in album release year
sunidhi
I was thinking some songs are released as singles (i.e. remixes), thus they wouldn't necessarily have an album associated with them. You don't need to create an album entry in order to save a track to the database. When I say author I mean the writer of the song (not always the performer).
Brian
okie ya true.. i got it
sunidhi
+4  A: 

I strongly recommend WWWSQLDesigner to design your database. Guideline that brianreavis had mentioned are really worthy of listening. Always use correct spelling, use consistent grammar, capitalization and underlining (_). Also you may consider adding multiple genres using a relationship table.

  album_genre ( id int, album int, genre int )

For album or artist pictures, I recommend you to save them to a folder with their related id's. Observe,

 id = 14
 artist = 42
 title = Mask And Mirror
 year = 1994

 thumbnail: /thumbnails/album-14.jpg
Cem Kalyoncu
I might add one more about WWWSQLDesigner, it also generates table creation queries from your design. Its a very handy tool. You can set it for your site in mere minutes.
Cem Kalyoncu
thanks for WWWSQLDesigner its make life easier
sunidhi
+2  A: 

Important questions you should be asking yourself while designing

  • What is my requirement!?! In your case, what all information should my lyrics website have? Should it tell me who actually wrote the song? When was it written? Who all have sung that song etc etc. So first thing is you have to define the scope! Your Entities and database design will depend on that!
  • What are my entities?
  • what are the relationships between my main entities?

Your design might be pretty descent and might work perfectly for your requirement but depending on how much of complexity you are willing to handle (requirement scope!), you might have to take care of things like:

  • Artist and Album actually have many to many relationship. Many artists might work on same album and of course a single artist will have multiple albums. Your current design will cope up with this but do you want genreId, title, release_year being duplicated when multiple artists work together for an album? There is a trade off involved here between creating 1 more table and storing duplicate values. Your current design might be perfect for what you are doing, but just wanted to make sure that you have given it a thought
  • In real world, multiple artists collaborate to write a song. Mostly songs are written by someone else and sung by someone else. You need to define what Artist means to you. Is it the person who sung the song? Is it someone who wrote the song? Are both artists? If I search for the writer of the song who has not sung a single song, should it return results?
  • I dont see a table where you are storing lyrics! But I guess you already know that :)

I can see a few more things which might cause you problems later on, but as I said, I don't know what is the scope of your requirement! :)

Tequila Guy
here is wht i did nowi added one more field as Artist_type to know its singer or writer.now i m not getting how to solve multiple artist thing.1 track sung by many singer or written by 2 or more writer
sunidhi
What if artist is both singer and writer? :) You'll run into lot of issues if u start designing and then think about requirement. I suggest, you first define the scope of your requirement, things like what all information your website will provide etc. You'll have much easier time designing once you have done that. Currently you are trying to hit a moving target.
Tequila Guy
can i store writer of the song in another table ?if song have diffrent writer then it create a record in writer table, if not it use same name as artrist... cos if i dont then it will be messy for me
sunidhi
A: 
sunidhi
Seriously: where are the lyrics going?
Dominic Rodger
tht actually i m confuse with.. sud i add tht field in track table. or i create a new table 'lyrics'
sunidhi
Probably put it in a separate table, and foreign key into it from `track`. That *might* improve query time as the number of items in the `track` table increases, given that the `lyrics` portion of the `track` table is likely to be large.
Dominic Rodger
A: 

I would use a framework that will enforce these relationships for you.

TIMEX
i m planing to use code igniter..but i m new in php mysql..
sunidhi
A: 

anyway i would seriously consider you guys take a look at :

http://www.findyourlyrics.com and see their sitemap and db structure.