TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 10-30-2007, 06:56 AM   #1 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default Database Structure - Comments?

I'm creating a lyrics script (as I have posted in another thread), and I was thinking today that my previous database structure wasn't great at all. I rethought it, and think that this new way might be a bit better, but I want to see what you guys think before I go with it.

I have 3 tables, albums, artists, and songs, which could all easily be used together (by JOIN's I believe?), to get the information where it's needed.



So is there any improvements I could make? The reason why I thought separate tables would be better, is to make it easier to make "Browse" pages on the site, and it still wouldn't take away much from getting all the info for a lyrics page.
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Old 10-30-2007, 11:45 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 1,547
Thanks: 72
Wildhoney is on a distinguished road
Default

The structure seems OK, it's just the naming conventions that I would alter. I would go for:
  • Albums
  • id (pk)
  • name
  • Artists
  • id (pk)
  • name (maybe even make this column unique, too)
  • Songs
  • id (pk)
  • album_id (fk)
  • artist_id (fk)
  • name
  • lyrics (consider using full-text search)

You'd set-up 2 relationships: songs.album_id => albums.id and songs.artist_id => albums.id.

Hope this helps!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 10-30-2007, 01:09 PM   #3 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 436
Thanks: 22
Karl is on a distinguished road
Default

This point isn't to do with your structure per se, but it's an important aspect of good database design. If you're using MySQL 5 you can setup relationships with cascades so that you can automatically update/delete related records. For example, with cascade deletes you can delete an artist, and MySQL will automatically delete the related records from the songs and albums table.
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 10-30-2007, 08:34 PM   #4 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 349
Thanks: 24
Haris is on a distinguished road
Default

Quote:
Originally Posted by Karl View Post
This point isn't to do with your structure per se, but it's an important aspect of good database design. If you're using MySQL 5 you can setup relationships with cascades so that you can automatically update/delete related records. For example, with cascade deletes you can delete an artist, and MySQL will automatically delete the related records from the songs and albums table.
And offtopic, that can be easily done via SQLYog. :)

I completely like that feature and hopefully is going to make a better use next time.

Thanks Karl.
Haris is offline  
Reply With Quote
Old 10-30-2007, 11:19 PM   #5 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

I'll take a look at that karl.

Also, for the names, I would have done that, I just put the prefix in there to be more clear.

Also, how would you guys recommend implementing an approved field, so neither the artist, album, or song shows up as approved until it is by an admin. I'd like to do it separately, so would just having an approved field in each table work?
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Old 10-31-2007, 01:24 AM   #6 (permalink)
The Wanderer
 
hostfreak's Avatar
 
Join Date: Oct 2007
Posts: 21
Thanks: 1
hostfreak is on a distinguished road
Default

In this case it is probably easier to just have an extra field in each table. Then just store a boolean value in the field; 0 being not approved (false), 1 being approved (true).

Otherwise, say for example you created another table and only approve so many songs per album, you would have a row for every approved/not approved song (sure, you could use a delimiter, but too much work). Overall, that would just be too much repeated data IMO.

Last edited by hostfreak : 10-31-2007 at 02:20 AM.
hostfreak is offline  
Reply With Quote
Old 10-31-2007, 01:41 AM   #7 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 1,547
Thanks: 72
Wildhoney is on a distinguished road
Default

Yep, I'd have to agree with hostfreak. Boolean in each table is definitely the approach I'd go for.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 10-31-2007, 01:54 AM   #8 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

Okay, I'll do that. :) Thanks for all your help.
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:52 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0